OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MSXML XPath question



Are there namespaces in the test_small.xml document? If so you will need to
provide a prefix mapping for the namespace URI(s) and then use those
prefixes in your XPath expressions. You specify the mappings through
setProperty;

    oXML.setProperty("SelectionNamespaces", "xmlns:a='urn:x1'
xmlns:b='urn:x2'");

And your XPath would then look like this ( assuming Index and document are
in the namespaces urn:x1 and urn:x2 respectively and that user is
unqualified);

    oDisplay = oXML.selectNodes("/a:Index/b:document[user='Joe Blow']");

if user is also in a namespace, say, the same one as document then you'd
need this;

    oDisplay = oXML.selectNodes("/a:Index/b:document[b:user='Joe Blow']");

Post a URL to your test_small.xml if the above doesn't fix it.

Regards

Martin Gudgin
DevelopMentor



----- Original Message -----
From: "White, Solomon" <Solomon_White@amr-corp.com>
To: "Xml-Dev Mailing List (E-mail)" <xml-dev@lists.xml.org>
Sent: Friday, May 18, 2001 8:55 PM
Subject: MSXML XPath question


> 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();
>   }
>
>
> ------------------------------------------------------------------
> The xml-dev list is sponsored by XML.org, an initiative of OASIS
> <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To unsubscribe from this elist send a message with the single word
> "unsubscribe" in the body to: xml-dev-request@lists.xml.org