Sign in to follow this  
Followers 0
jpam

xml

6 posts in this topic

#1 ·  Posted (edited)

please!

Need help with parsing xml file

what i have so far

$xmlDoc = ObjCreate("Msxml2.DOMdocument.3.0")

$xmlDoc.load("C:\books.xml")

;extract id

$nodeBook = $xmlDoc.selectSingleNode("//book")

$nodeId = $nodeBook.attributes.getNamedItem("id")

MsgBox(64,"",$nodeId.value)

;extract authors

$NodeList = $xmlDoc.getElementsByTagName("author")

for $i=0 To $NodeList.length

$value = $NodeList.item($i).text

MsgBox(64,"",$value)

Next

Extracting the authors is doing well ,exept on the end of the xml file i got an error :)

what is want is all the id' s like the authors

can somebody help me with this?

thanks in advance

jpam,

books.xml

Edited by jpam

Share this post


Link to post
Share on other sites



Isn't should loop be:

for $i=0 To $NodeList.length - 1
...

?

i see no difference in my script example

with or without the -1

Share this post


Link to post
Share on other sites

yep !

your right lazycat!

the missing -1

that causes the error on the end of the xml file

only problem for me is extracting the id's now

anybody??

Share this post


Link to post
Share on other sites

yep !

your right lazycat!

the missing -1

that causes the error on the end of the xml file

only problem for me is extracting the id's now

anybody??

Hm, you already have code for select "author" nodes. What the difference for select id's?

$NodeList = $xmlDoc.selectNodes("book")
for $i=0 To $NodeList.length - 1
    $value = $NodeList.item($i).getAttribute("id")
    MsgBox(64,"",$value)
Next

Share this post


Link to post
Share on other sites

Hm, you already have code for select "author" nodes. What the difference for select id's?

$NodeList = $xmlDoc.selectNodes("book")
for $i=0 To $NodeList.length - 1
    $value = $NodeList.item($i).getAttribute("id")
    MsgBox(64,"",$value)
Next

Thanks a million lazycat !

you put me on the right track :)

only thing that was missing is the 2 backslashes

$NodeList = $xmlDoc.selectNodes("//book")

now its working fine :(

thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0