Page History
...
ExampleXML
Introduction to XML Path Language (XPath)
XPath Examples for use with XMLQueryService
XML Namespaces and How They Affect XPath Expressions for XMLQueryService
Example XML
The examples provided later in this section will refer to the following simple example XML document:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Orders SYSTEM "http://www.acme.com/schemas/tutorder.dtd" >
<Orders>
<SalesOrder SONumber="12345">
<Customer CustNumber="543">
<CustName>ABC Industries</CustName>
<Street>123 North St.</Street>
<City>Bankstown</City>
<State>NSW</State>
<PostCode>2087</PostCode>
</Customer>
<OrderDate>2012-11-19</OrderDate>
<Line LineNumber="1">
<Part PartNumber="123">
<Description>Gasket Paper</Description>
<Price>9.95</Price>
</Part>
<Quantity>10</Quantity>
</Line>
<Line LineNumber="2">
<Part PartNumber="456">
<Description>Glue</Description>
<Price>13.27</Price>
</Part>
<Quantity>5</Quantity>
</Line>
</SalesOrder>
</Orders>
Introduction to XML Path Language (XPath)
XPath is a syntax for constructing path expressions to select nodes in an XML document. To some extent, these path expressions look very similar to path expressions you use when working with the file system on your computer.
...
| Note |
|---|
| Important note: XML node names are case sensitive. Your XPath expressions must specify the correct case when specifying element and attribute names. For example, the expression '//salesorder' is NOT the same as '//SalesOrder'. When used with the example XML document shown above, the former expression will FAIL to select ANY nodes, while the latter will select all <SalesOrder> elements, wherever they occur in the document. |
XPath Examples for use with XMLQueryService
The following examples use XPath expressions in the parameters of the QUERY command of the XMLQueryService to select values from the example XML document shown above.
...
QUERY NODES(//Part[Price>2.99])
NODESVALUE1(../../@SONumber)
NODESVALUE2(@PartNumber)
NODESVALUE3(Price)
NODESVALUE4(../Quantity)
NODESVALUE5(Price*../Quantity)
XML Namespaces and How They Affect XPath Expressions for XMLQueryService
The examples used so far operate on an XML document that contains no explicit namespace declarations and does not make use of namespace prefixes. This is the simplest case but frequently does not reflect the real world.
...