The XML Example Document: View The "Books - XML" File in Your Browser
The XML Example Document: View The "Books - XML" File in Your Browser
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 .
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
Example
2booksto e2book2title ? , it ,ou self K
?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
Example
2booksto e2book2p ice2textBC ? , it ,ou self K
?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
Example
2booksto e2bookLp ice+5)M2title