Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-13
3
Medium Priority
?
641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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