[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
MSXML XPath question
- From: "White, Solomon" <Solomon_White@amr-corp.com>
- To: "Xml-Dev Mailing List (E-mail)" <xml-dev@lists.xml.org>
- Date: Fri, 18 May 2001 13:55:37 -0600
Hello all--
I have a question regarding the use of XPath in IE5+. What I am trying to
do is build an html page that loads xml data from a file, then gives users
the ability to filter/sort the data. The way I am attempting to go about
this is as follows (see actual code below):
1) on page load, create MSXML2.DOMDocument object, load data, set selection
language of object to XPath.
2) Select all nodes ("/") into a "display" object
3) Loop through display object, creating rows/cells in an HTML table
4) When the user specifies a filter, reset display object to have only
selected records from original XML object, clear the table, then repeat step
3 to display only selected records.
This all works except step 4. I do not get any errors, but all records are
displayed instead of the selection. BTW, I tried my XPath query string in
an XPath validation page, and it validates correctly.
Any ideas?
------CODE SNIPPETS FOLLOW----
//this code creates the necessary objects
var oXML = new ActiveXObject("MSXML2.DOMDocument");
oXML.async = false;
oXML.validateOnParse=false;
if (! oXML.load("test_small.xml")) {
alert("unable to load test_small.xml");
}
oXML.setProperty("SelectionLanguage", "XPath");
var oDisplay = oXML.selectNodes("/");
function load_data() {
//display all data in oDisplay in HTML table
//empty the table
while (tblXML.rows.length > 0) {
tblXML.deleteRow();
}
//add XML content to table
var root = oDisplay.context.firstChild;
for (i=0; i<root.childNodes.length; i++) {
var doc = root.childNodes(i);
var oRow = tblXML.insertRow();
for (j=0; j<doc.childNodes.length; j++) {
var oCell = oRow.insertCell();
oCell.innerHTML = doc.childNodes(j).xml;
}
}
}
function doFilter() {
//oDisplay = oXML.selectNodes("/Index/document[starts-with(user,'J')]");
oDisplay = oXML.selectNodes("/Index/document[user='Joe Blow']");
load_data();
}