Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • Last Modified:

Get values of an attibute for all elements in an XML file (using VBscript)

How can I get the values of an attibute for an element in an XML file using VBscript.
0
ENTPF
Asked:
ENTPF
  • 2
1 Solution
 
yehudahaCommented:
read this:

http://www.devguru.com/technologies/xml_dom/15891.asp

xml file in my example:

<staff>
   <employee ssn="123456" pay="3">
      <f_name>John</f_name>
      <l_name>Sullivan</l_name>
   </employee>
   <employee ssn="987654" pay="2">
      <f_name>Mary</f_name>
      <l_name>Lopez</l_name>
   </employee>
</staff>

output:

staff
employee
f_name
l_name
employee
f_name
l_name

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("c:\staff.xml")
 
Set NodeList = objXMLDoc.getElementsByTagName("*")
For Each Elem In NodeList
   WScript.Echo Elem.tagName 
Next

Open in new window

0
 
ENTPFAuthor Commented:
what I need is to get the value for the 'ssn' attribute.  I need it to return '123456' ( in your example). How can this be coded using vbscript?
0
 
yehudahaCommented:
ok

here:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.load("c:\staff.xml")
 
Set objFirstChild = objXMLDoc.documentElement.firstChild
Set objAttributes = objFirstChild.attributes
For Each Attribute in objAttributes
   WScript.Echo Attribute.name & " Value: " & Attribute.value 
Next

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now