| t;title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
.
.
.
.
</catalog>
If you have IE 5 or higher you can look at the cdcatalog.xml.
Selecting Nodes
We will demonstrate how to select nodes from the XML document by using the selectNodes function in Internet Explorer. This function takes a location path expression as an argument:
xmlobject.selectNodes(XPath expression)
Selecting cd Nodes
The following example selects all the cd nodes from the CD catalog:
xmlDoc.selectNodes("/catalog/cd")
If you have IE 5 or higher you can try it yourself.
Selecting the First cd Node
The following example selects only the first cd node from the CD catalog:
xmlDoc.selectNodes("/catalog/cd[0]")
If you have IE 5 or higher you can try it yourself.
Note: IE 5 has implemented that [0] should be the first node, but according to the W3C standard it should have been [1].
Selecting price Nodes
The following example selects all the price nodes from the CD catalog:
xmlDoc.selectNodes("/catalog/cd/price")
If you have IE 5 or higher you can try it yourself.
Selecting price Text Nodes
The following example selects only the text from the price nodes:
xmlDoc.selectNodes("/catalog/cd/price/text()")
If you have IE 5 or higher you can try it yourself.
Selecting cd Nodes with Price>10.80
The following example selects all the cd nodes with a price>10.80:
xmlDoc.selectNodes("/catalog/cd[price>10.80]")
If you have IE 5 or higher you can try it yourself.
Selecting price Nodes with Price>10.80
The following example selects all the price nodes with a price>10.80:
xmlDoc.selectNodes("/catalog/cd[price>10.80]/price")
If you have IE 5 or higher you can try it yourself.
上一页 [1] [2] [3] [4] |