User Tools

Site Tools


XPATH

Guide Section: Processing Object Data | EASAP Tree: DATA PROCESSING LIST


XPath is a standard xml query language with many references and tutorials available on the internet.

XPATH supports XPath version 1.0.

  • XPATH uses XPath path expressions to select nodes or node-sets in an XML document either from,
    • File: with an xml file
      • or
    • Value: completed with SCALAR reference or literal string of xml
XPATH
Essential Parameters:
Query:The XPath query to run, which may contain object references
Optional Parameters:
Value:This should be used if the xml to parse is in a SCALAR reference.
File:This should be used if the xml to parse is in a file.
Show Complete Results:If the query matches a node, this allows child nodes to be returned also. (default→TRUE).
Show Attribute Values:When matching an attribute the query can return: Name, Value or both. (default→Value).
Use Namespaces:For large xml files that do not use namespaces, setting this to FALSE can improve performance.
Default Namespace Prefix:If the xml file contains entries such as xmlns=”…, rather than xmlns:mynamespace=”…, then this parameter allows a default namespace to be specified and that namespace may be used within Xpath queries.
Encoding:This is used in conjunction with File: to specify the file type. The default type is 'UTF-8'
Delimiter:Character to delimit the SCALAR reference in Value:(default→%).

Our example follows the example at the external page:

Create the xml file below:

bookstore.xml
  <?xml version="1.0" encoding="UTF-8"?>
   <bookstore>
    <book>
     <title lang="en">Harry Potter</title>
     <price>29.99</price>
    </book>
    <book>
     <title lang="en">Learning XML</title>
     <price>39.95</price>
   </book>
  </bookstore>
File: → bookstore.xml example above Output Values
Query:/bookstore/book[1]/title/child::text() Harry Potter
Query:/bookstore/book[1] <book> <title> Harry Potter</title><price> 29.99</price></book>
Query:/bookstore/book[1]/title/@lang en
Query:/bookstore/book[1]/title
Show Complete Results: NO
<title lang=“en”/>

The Tree and EASAP output for these four Query: parameters:


Page Tools