0% found this document useful (0 votes)
79 views4 pages

The XML Example Document: View The "Books - XML" File in Your Browser

The document provides an XML example file called "books.xml" containing book data. It then discusses loading the XML file using XMLHttpRequest and selecting nodes from the XML document using different methods that work across browsers like selectNodes and evaluate. It provides examples of selecting all titles, the first book title, all prices, and titles and prices that meet certain criteria to demonstrate these node selection techniques.

Uploaded by

ravikumar4it
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views4 pages

The XML Example Document: View The "Books - XML" File in Your Browser

The document provides an XML example file called "books.xml" containing book data. It then discusses loading the XML file using XMLHttpRequest and selecting nodes from the XML document using different methods that work across browsers like selectNodes and evaluate. It provides examples of selecting all titles, the first book title, all prices, and titles and prices that meet certain criteria to demonstrate these node selection techniques.

Uploaded by

ravikumar4it
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

The XML Example Document

We will use the following XML document in the examples below. "books.xml": <?xml ve sion!"".#" encoding!"$%&'(()*'""?+ <booksto e+ <book catego ,!"-&&.$/0"+ <title lang!"en"+1ve ,da, $talian<2title+ <autho +0iada 3e Lau entiis<2autho + <,ea +4##)<2,ea + <p ice+5#.##<2p ice+ <2book+ <book catego ,!"-6$L371/"+ <title lang!"en"+6a , 8otte <2title+ <autho +9 .. 7owling<2autho + <,ea +4##)<2,ea + <p ice+4*.**<2p ice+ <2book+ <book catego ,!"W1:"+ <title lang!"en"+X;ue , .ick %ta t<2title+ <autho +9ames Mc0ove n<2autho + <autho +8e :othne <2autho + <autho +.u t -agle<2autho + <autho +9ames Linn<2autho + <autho +<aid,anathan /aga a=an<2autho + <,ea +4##5<2,ea + <p ice+>*.**<2p ice+ <2book+ <book catego ,!"W1:"+ <title lang!"en"+Lea ning XML<2title+ <autho +1 ik ?. 7a,<2autho + <,ea +4##5<2,ea + <p ice+5*.*)<2p ice+ <2book+ <2booksto e+ <iew the "books.xml" file in ,ou b owse .

Loading the XML Document


@sing XML6ttp7eAuest to load XML documents is suppo ted in all mode n b owse s. -ode fo most mode n b owse s: va xmlhttp!new XML6ttp7eAuestBC -ode fo old Mic osoft b owse s B$1 ) and DC: va xmlhttp!new EctiveX&b=ectB"Mic osoft.XML6??8"C

Selecting Nodes
@nfo tunatel,F the e a e diffe ent wa,s of dealing with X8ath in $nte net 1xplo e and othe b owse s. $n ou examples we have included code that should wo k with most ma=o b owse s. $nte net 1xplo e uses the select/odesBC method to select nodes f om the XML document: xml3oc.select/odesBxpathCG Hi efoxF -h omeF &pe a and %afa i use the evaluateBC method to select nodes f om the XML document: xml3oc.evaluateBxpathF xml3ocF nullF X8ath7esult.E/IJ?I81FnullCG

Select all the titles


?he following example selects all the title nodes:

Example
2booksto e2book2title ? , it ,ou self K

Select the title of the first book

?he following example selects the title of the fi st book node unde the booksto e element:

Example
2booksto e2bookL"M2title ? , it ,ou self K ?he e is a p oblem with this. ?he example above shows diffe ent esults in $1 and othe b owse s. $1) and late has implemented that L#M should be the fi st nodeF but acco ding to the W5standa d it should have been L"MNN

A Workaround
?o solve the L#M and L"M p oblem in $1)OF ,ou can set the %electionLanguage to X8ath. ?he following example selects the title of the fi st book node unde the booksto e element:

Example
xml.set8 ope t,B"%electionLanguage"F"X8ath"CG xml.select/odesB"2booksto e2bookL"M2title"CG ? , it ,ou self K

Select all the prices


?he following example selects the text f om all the p ice nodes:

Example
2booksto e2book2p ice2textBC ? , it ,ou self K

Select price nodes !ith price"#$

?he following example selects all the p ice nodes with a p ice highe than 5):

Example
2booksto e2bookLp ice+5)M2p ice ? , it ,ou self K

Select title nodes !ith price"#$


?he following example selects all the title nodes with a p ice highe than 5):

Example
2booksto e2bookLp ice+5)M2title

You might also like