|
-
Feb 16th, 2012, 01:10 PM
#1
Thread Starter
New Member
VB script for Parsing XML attributes
HI,
I am trying to develop a script which can parse all nodes/elements and its attributes of an XML.
I am able to read all nodes/elements but not attributes of it like
<article id="474544c" language="eng" publish="issue" relation="no" origsrc="yes">
Can you please help me to going in parse all elements/attributes of XML given below
My XML:
------
<?xml version="1.0"?>
<article id="474544c" language="eng" publish="issue" relation="no" origsrc="yes">
<entity-declarations>
<entity id="illus1" url="474544c-i1.0.jpg"/>
</entity-declarations>
<pubfm>
<jtl>Nature</jtl>
<vol>474</vol>
<iss>7353</iss>
<idt>20110630</idt>
<section id="this-week"/>
<categ id="rhighlts"/>
<pp><spn>544</spn><epn>544</epn><cnt>1</cnt></pp>
<issn type="print">0028-0836</issn>
<issn type="electronic">1476-4687</issn>
<cpg><cpy>2011</cpy><cpn>Nature Publishing Group, a division of Macmillan Publishers Limited. All Rights Reserved.</cpn></cpg>
<subject code="npg_subject_326"/>
<doi>10.1038/474544c</doi></pubfm>
<fm>
<atl><topic>Biology</topic> Algal synchronized swimming</atl>
<hst><pubdate type="iss" year="2011" month="06" day="29"/></hst></fm>
<bdy>
<p>Suspensions of swimming algal cells form intricate mottled patterns that are governed by a complex interplay between light, gravity and fluid dynamics. The patterns (<b>pictured</b>) change with shifting lighting conditions, which could one day be exploited to improve the yields of bioreactors that use algae to produce biofuel.</p>
<p>Rosie Williams and Martin Alan Bees of the University of Glasgow, UK, studied the patterns formed by suspensions of <i>Chlamydomonas augustae</i> cells in response to changes in the orientation and intensity of the light source. As overhead white light grew brighter, dense groups of cells first moved apart, then drew closer together. When the algae were lit from below, brighter light resulted in a shortening and then a levelling off of distances between dense cell groups.</p>
<p>Such pattern changes could be exploited to increase the penetration of light and nutrients to cell suspensions, and to concentrate cells for harvesting.<illusr rid="i1" align="left"/></p>
<p><cite id="n1"><jtl>J. Exp. Biol.</jtl> <vid>24</vid>, <ppf>2398</ppf>–<ppl>2408</ppl> (<cd year="2011">2011</cd>) <refdoi display="hide">10.1242/jeb.051094</refdoi></cite></p></bdy>
<bm>
<objects>
<illus id="i1" type="eps" entref="illus1">
<credit>M. A. BEES</credit></illus></objects></bm></article>
My VB script Code:
------------------
Dim goFS
Set goFS = CreateObject( "Scripting.FileSystemObject" )
Dim sDir
sDir = "C:\work"
Dim oXDoc
Set oXDoc = CreateObject( "Msxml2.DOMDocument" )
oXDoc.async = False
Dim oFile
For Each oFile In goFS.GetFolder( sDir ).Files
WScript.Echo "looking at", oFile.Name
WScript.Echo "will load", oFile.Path
If oXDoc.load( oFile.Path ) Then
WScript.Echo "successfully loaded", oFile.Name
End If
Next
Set ndlEventId = oXDoc.documentElement.selectNodes("//*")
for i = 0 to ndlEventId.length-1
WScript.Echo ndlEventId(i).nodeName & " :: " &ndlEventId(i).text
If ndlEventId(i).text="" Then
s=ndlEventId(i).nodeName
WScript.Echo s
Set attrvalue=oXDoc.getAttribute(s)
WScript.Echo attrvalue
End if
Next
Thanks in advance
Bhaskar
-
Feb 16th, 2012, 05:31 PM
#2
Addicted Member
Re: VB script for Parsing XML attributes
Try incorporating this into your code:
Code:
For j = 0 To ndlEventId(i).attributes.length - 1
Wscript.Echo "Attribute " & ndlEventId(i).attributes(j).name & " = " & ndlEventId(i).attributes(j).value
Next
-
Feb 17th, 2012, 05:22 AM
#3
Thread Starter
New Member
Re: VB script for Parsing XML attributes
Just.. the way i want.. it works..
Thanks mate
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|