[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

MSXML XPath question

  • From: "White, Solomon" <Solomon_White@a...>
  • To: "Xml-Dev Mailing List (E-mail)" <xml-dev@l...>
  • Date: Fri, 18 May 2001 13:55:37 -0600

msxml xpath
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();
  }


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.