Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

11 Experts available now in Live!

Get 1:1 Help Now