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

RE: MSXML XPath question

  • From: Derek Denny-Brown <derekdb@m...>
  • To: "White, Solomon" <Solomon_White@a...>,"Xml-Dev Mailing List (E-mail)" <xml-dev@l...>
  • Date: Fri, 18 May 2001 15:23:55 -0700

msxml childnodes
Rather than walking the children of the results from the selectNodes,
you should just iterate over the selection as a collection object.

I haven't tested this code, but it should work.  Also note that I change
for your 'for' loop to a more efficient 'while' loop.  For large
datasets, using the nextNode() method can be _much_ more efficient.
 
    //add XML content to table
    var oNode;
    while ( null != (oNode = oDisplay.nextNode())) {
      var oRow = tblXML.insertRow();
      var oChildren = oNode.childNodes;
	var oChild;
      while ( null != (oChild = oChildren.nextNode())) {
        var oCell = oRow.insertCell();
        oCell.innerHTML = oChild.xml;
      }
    }

Derek Denny-Brown
-- Technical Lead: MSXML --
<http://msdn.microsoft.com/xml>

> -----Original Message-----
> From: White, Solomon [mailto:Solomon_White@a...]
> Sent: Friday, May 18, 2001 12:56 PM
> To: Xml-Dev Mailing List (E-mail)
> 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@l...
> 

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.