perfectxml.com
 Basic Search  Advanced Search   
Topics Resources Free Library Software XML News About Us
  You are here: home »» Focus »» MSXML » XPath Saturday, 23 February 2008
 
NEWS
MSXML 4.0 SP2 now available!

 
MSXML
Basics
DOM
SAX
XPath
XSLT
Schemas
SOM
HTTP Access
.NET
Data Islands
Ask a Question
   Past Q&As
C++ Samples
DLL/Version Info
Reference Guide
Books
KB Articles
   HOW TO
   SAMPLE
   INFO
   BUG/PRB
   FIX
   Misc.
MSXML Tips
   August 2002
   September 2002
MSXML Tools

Microsoft XML Core Services

XPath or XML Path Language is a W3C Specification that is designed to be used to address parts of an XML document. XPath expressions provide an uniform and compact syntax that can be used to look for nodes that match some criteria, instead of writing code to explicitly walk through a document's structure. XPath is generally used in conjunction with XSLT. MSXML supports XPath 1.0.

      Tip: Chapter 4 [XPath in MSXML] in the book XML Application Development with MSXML 4.0 covers MSXML XPath implementation details in great details.

  • MSXML 3.0 XPath Documentation

  • MSXML 3.0 XPath Reference

  • MSXML 4.0 XPath Documentation

  • MSXML 4.0 XPath Reference

      Don't forget to check out 50 XSLT Tips and XPath/XSLT Quiz.

Interactive XPath expression builder by Aaron Skonnard:

(MSXML 3.0 version   MSXML 4.0 version   MSXML Version Independent)

Example: Try XPath Expression: /Invoices/Invoice/LineItems/LineItem[Sku='134']/Price/node()


      Tip: Check out an excellent article on XPath by Aaron Skonnard.

Let's look at JavaScript example to use XPath expressions with MSXML:

Conside following sample XML document (c:\soapres.xml):
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Body>
                <AddResponse>
                        <sum>100</sum>
                </AddResponse>
        </soap:Body>
</soap:Envelope>

JavaScript

<script language="JScript">
<!--
try
{
var objDOMDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
objDOMDoc.async = false;
if (objDOMDoc.load("c:\\soapres.xml"))
{
  objDOMDoc.setProperty("SelectionNamespaces", "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'");
  alert(objDOMDoc.selectSingleNode("/soap:Envelope/soap:Body/AddResponse/sum").nodeTypedValue);
}
else
{
  alert("Error: " + objDOMDoc.parseError.reason);
}
}
catch(e)
{
        alert("Error: " + e);
}
//-->
</script>

MSXML XPath Resources Around the Web

  • Object Graphs, XPath, String Comparisons, and More
  • MSXML XPath KB Articles
  • Addressing Infosets with XPath
  • XPath in MSXML
  Contact Us |  | Site Guide | About PerfectXML | Advertise ©2004 perfectxml.com. All rights reserved. | Privacy