how to select a node from xml file?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Below is my xml file
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UTF-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; bookstore<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; book <span style="color:Red; category<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; cooking<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; bookID<span style="color:Blue; >1111<span style="color:Blue; </<span style="color:#A31515; bookID<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title <span style="color:Red; lang<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; en<span style="color:Black; "<span style="color:Blue; >Everyday Italian<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >Giada De Laurentiis<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >2005<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >30.00<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; book <span style="color:Red; category<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; children<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; bookID<span style="color:Blue; >54655<span style="color:Blue; </<span style="color:#A31515; bookID<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title <span style="color:Red; lang<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; en<span style="color:Black; "<span style="color:Blue; >Harry Potter<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >J K. Rowling<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >2005<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >29.99<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; book <span style="color:Red; category<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; web<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; bookID<span style="color:Blue; >5556<span style="color:Blue; </<span style="color:#A31515; bookID<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title <span style="color:Red; lang<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; en<span style="color:Black; "<span style="color:Blue; >XQuery Kick Start<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >James McGovern<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >Per Bothner<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >Kurt Cagle<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >James Linn<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >Vaidyanathan Nagarajan<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >2003<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >49.99<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; book <span style="color:Red; category<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; web<span style="color:Black; " <span style="color:Red; cover<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; paperback<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; bookID<span style="color:Blue; >1111<span style="color:Blue; </<span style="color:#A31515; bookID<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; title <span style="color:Red; lang<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; en<span style="color:Black; "<span style="color:Blue; >Learning XML<span style="color:Blue; </<span style="color:#A31515; title<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; author<span style="color:Blue; >Erik T. Ray<span style="color:Blue; </<span style="color:#A31515; author<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; year<span style="color:Blue; >2003<span style="color:Blue; </<span style="color:#A31515; year<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; price<span style="color:Blue; >39.95<span style="color:Blue; </<span style="color:#A31515; price<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; book<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; bookstore<span style="color:Blue; >
[/code]
<br/>
I need to display "Title" of the books.
Below asp code i used to display data

<div style="color:Black;background-color:White; <pre>
<span style="background-color:Yellow; <%
Load XML

Set xml= Server.CreateObject("Msxml2.DOMDocument.3.0")
xml.async = False
xml.load (Server.MapPath("test.xml"))

if xml.parseError.errorcode<>0 then
response.write "error handling code" &xml.parseError.errorcode
else

Set objLst= xml.getElementsByTagName("bookstore").item(0).getElementsByTagName("book")
TotalBooks = (objLst.Length)-1
For i=0 to eval(TotalBooks)
response.write xml.getElementsByTagName("bookstore").item(0).getElementsByTagName("book").item(i).getElementsByTagName("title").item(0).text&"<br/>"
Next

end if

<span style="background-color:Yellow; %>
[/code]

<br/>
But "objLst.length" showing the sub node of <book>
in this cause i getting error
the code display only the fist node book title only . it not goes to the second node. hw i fix it?

i need out put like below
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML

View the full article
 
Back
Top