Solved

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

Posted on 2009-04-13
3
634 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now