Solved

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

Posted on 2009-04-13
3
635 Views
Last Modified: 2012-05-06
How can I get the values of an attibute for an element in an XML file using VBscript.
0
Comment
Question by:ENTPF
  • 2
3 Comments
 
LVL 14

Expert Comment

by:yehudaha
ID: 24132099
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
 

Author Comment

by:ENTPF
ID: 24132390
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
 
LVL 14

Accepted Solution

by:
yehudaha earned 500 total points
ID: 24132462
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question