| <html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>How to use the XPath 2.0 grammar with PsychoPath</title><link href="book.css" rel="stylesheet" type="text/css"><link href="../book.css" rel="stylesheet" type="text/css"><meta content="DocBook XSL Stylesheets V1.74.0" name="generator"><link rel="home" href="index.html" title="XPath 2.0 Processor User Manual"><link rel="up" href="ch02.html" title="Using PsychoPath XPath 2.0 API"><link rel="prev" href="ch02s02.html" title="Schema Aware"><link rel="next" href="ch02s03s02.html" title="Path expressions"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="How_to_use_the_XPath_2.0_grammar_with_PsychoPath"></a>How to use the XPath 2.0 grammar with PsychoPath</h2></div></div></div><p>In this section we will try to give you an overview of the XPath | |
| 2.0 grammar in general and how each production in the grammar should be | |
| used with PsychoPath. For the formal specifications, see the W3C | |
| web-site for XPath 2.0 specification <a class="ulink" href="http://www.w3.org/TR/xpath20" target="_top">http://www.w3.org/TR/xpath20</a>.</p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="Constants"></a>Constants</h3></div></div></div><p>String literals are written as “Hello” or ‘Hello’. In each case | |
| the opposite kind of quotation mark can be used within the string: ‘He | |
| said “Hello” ’ or “London is a big city”. To feed PsychoPath, “ ‘Hello | |
| World!’ ”or “ “Hello World!” ” can be used to feed it with strings. | |
| Remember that the ResultSequence returns AnyType so since a string is | |
| being expected as the result, first it has to be casted in the code | |
| like this: <pre class="programlisting">XSString xsstring = (XSString)(rs.first());</pre> | |
| Numeric constants follow the Java rules for decimal literals: for | |
| example, 4 or 4.67; a negative number can be written as -3.05. The | |
| numeric literal is taken as a double precision floating point number | |
| if it uses scientific notation (e.g. 1.0e7), as a fixed point decimal | |
| if it includes a decimal point, or as an integer otherwise. When | |
| extracting number literals from the ResultSequence, possible types to | |
| be returned include <span class="italic">XSDecima''l (e.g. : | |
| xs:decimal: 4.67),''XSInteger ''(e.g. : xs:integer: 4) or | |
| ''XSDouble</span> (e.g. : xs:double 1e0). All of which need to be | |
| cast in the same manner as stated before: from AnyType to their | |
| corresponding types.</p><p>There are no boolean constants as such: <span class="italic">true, false</span> instead the function calls | |
| <span class="bold"><strong>true()</strong></span> and <span class="bold"><strong>false()</strong></span> are used.</p><p>Constants of other data types can be written using constructors. | |
| These look like function calls but require a string literal as their | |
| argument. For example, <span class="bold"><strong>xs:float(“10.7”)</strong></span> produces a single-precision | |
| floating point number.</p></div></div></body></html> |