This link has been bookmarked by 39 people . It was first bookmarked on 02 Mar 2006, by Liuhan.
-
18 Jun 15
-
16 Jan 15
-
03 Jul 14
-
Loading the XML Document
Using XMLHttpRequest to load XML documents is supported in all modern browsers.
Code for most modern browsers:
var xmlhttp=new XMLHttpRequest()Code for old Microsoft browsers (IE 5 and 6):
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") -
Selecting Nodes
-
Internet Explorer uses the selectNodes() method to select nodes from the XML document:
xmlDoc.selectNodes(xpath); -
Firefox, Chrome, Opera and Safari use the evaluate() method to select nodes from the XML document:
xmlDoc.evaluate(xpath, xmlDoc, null, XPathResult.ANY_TYPE,null); -
/bookstore/book/title
-
/bookstore/book[1]/title
-
/bookstore/book/price[text()]
-
/bookstore/book[price>35]/price
-
/bookstore/book[price>35]/title
-
-
14 May 13
-
Firefox, Chrome, Opera and Safari use the evaluate() method to select nodes from the XML document:
-
-
29 Mar 13
-
Using XMLHttpRequest to load XML documents is supported in all modern browsers.
-
/bookstore/book/title
-
/bookstore/book[1]/title
-
/bookstore/book/price/text()
-
/bookstore/book[price>35]/price
-
/bookstore/book[price>35]/title
-
-
28 Aug 12
-
books.xml
-
XMLHttpRequest to load XML documents
-
Internet Explorer uses the selectNodes()
-
evaluate()
-
-
07 Jul 12
-
nternet Explorer uses the selectNodes() method to select nodes from the XML document:
-
-
12 Mar 12
-
24 Aug 11
lwaitsSelect title nodes with price>35
The following example selects all the title nodes with a price higher than 35: -
24 Sep 10
-
17 Aug 10
-
29 Jul 10
-
14 Jul 10
-
15 Jan 10
-
08 Nov 08
-
13 Nov 07
-
04 Aug 06
-
17 Feb 06
-
The XML Example Document
We will use the following XML document in the examples below.
"books.xml":
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="COOKING"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book>
<book category="CHILDREN"> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book>
<book category="WEB"> <title lang="en">XQuery Kick Start</title> <author>James McGovern</author> <author>Per Bothner</author> <author>Kurt Cagle</author> <author>James Linn</author> <author>Vaidyanathan Nagarajan</author> <year>2003</year> <price>49.99</price> </book>
<book category="WEB"> <title lang="en">Learning XML</title> <author>Erik T. Ray</author> <year>2003</year> <price>39.95</price> </book>
</bookstore>
View the "books.xml" file in your browser.
Selecting Nodes
We will use the Microsoft XMLDOM object to load the XML document and the selectNodes() function to select nodes from the XML document:
set xmlDoc=CreateObject("Microsoft.XMLDOM") xmlDoc.async="false" xmlDoc.load("books.xml")xmlDoc.selectNodes(path expression)
Select all book Nodes
The following example selects all the book nodes under the bookstore element:
xmlDoc.selectNodes("/bookstore/book")If you have IE 5 or higher you can try it yourself.
Select the First book Node
The following example selects only the first book node under the bookstore element:
xmlDoc.selectNodes("/bookstore/book[0]")If you have IE 5 or higher you can try it yourself.
Note: IE 5 and 6 has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!
Select the prices
The following example selects the text from all the price nodes:
xmlDoc.selectNodes("/bookstore/book/price/text()")If you have IE 5 or higher you can try it yourself.
Selecting price Nodes with Price>35
The following example selects all the price nodes with a price higher than 35:
xmlDoc.selectNodes("/bookstore/book[price>35]/price")If you have IE 5 or higher you can try it yourself.
Selecting title Nodes with Price>35
The following example selects all the title nodes with a price higher than 35:
xmlDoc.selectNodes("/bookstore/book[price>35]/title")
-
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.