FPath

From JRapid

Jump to: navigation, search

FPath is an XPath based language. It was created by JRapid to query property values in forms.

Contents

Usage:

FPath and XPath syntax are very similar. In the following section we describe the main differences.

For the following examples, the following XML will be used:


<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore>


  • FPath expressions do not start with the root element.

e.g: Select the first book in the bookstore:

XPath expression: "/bookstore/book[1]"

FPath expression: "/book[1]"

Result:

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>


  • FPath expressions use '.' to access child elements.

e.g: Access the title of the first book:

XPath expression: "/bookstore/book[1]/title"

FPath expression: "book[1].title"

Result: "Harry Potter"


  • FPath expressions use '[*]' to match all the children of an element.

e.g: Selecting all the books of the bookstore:

XPath expression: "/bookstore/book"

FPath expression: "book[*]"

Result:

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>


  • The '.' FPath expression is resolved as '/@id

The '.' character is used when an entity is passed as parameter.

Operators:

FPath uses the same operators as XPath. A table with the available operators is listed below:

Operator Description Example Return value
| Computes two node-sets //book | //cd Returns a node-set with all book and cd elements
+ Addition 6 + 4 10
- Subtraction 6 - 4 2
* Multiplication

6 * 4

24
div Division 8 div 4 2
= Equal price=9.80

true if price is 9.80
false if price is 9.90

!= Not equal price!=9.80

true if price is 9.90

false if price is 9.80
< Less than price<9.80

true if price is 9.00

false if price is 9.80
<= Less than or equal to price<=9.80

true if price is 9.00

false if price is 9.90
> Greater than price>9.80

true if price is 9.90

false if price is 9.80
>= Greater than or equal to price>=9.80

true if price is 9.90

false if price is 9.70
or or price=9.80 or price=9.70

true if price is 9.80

false if price is 9.50
and and price>9.00 and price<9.90

true if price is 9.80

false if price is 8.50
mod Modulus (division remainder) 5 mod 2 1

Example:

In the following example an Invoice element with "id" = 2 is opened,

FPath example

XML response for the Invoice /xml/Invoice/2 web service :

<invoice id="2" style="">
   <company id="14" style="">
      <name>Proda Software</name> 
   </company>
   <address>Cordoba 883</address> 
   <date>13/01/2010</date> 
   <subtotal>80</subtotal> 
   <discount>0</discount> 
   <total>80</total> 
   <orderDetail id="4" style="">
      <invoice id="2" style="">
         <company id="14" style="">
            <name>Proda Software</name> 
         </company>
      </invoice>
      <qty>1</qty> 
      <product id="3" style="">
         <name>Keyboard</name> 
      </product>
      <unitPrice>80</unitPrice> 
      <totalPrice>80</totalPrice> 
   </orderDetail>
</invoice>
  • The "subtotal" value is the sum of all the "totalPrice" elements that are children of the "orderDetail" element.
<property calculated="sum(orderDetail[*].totalPrice)" label="Subtotal" name="subtotal" type="integer"/>
  • The "total" value is calculated by substracting the discount from the "subtotal" value:
<property calculated="subtotal * (1 - 5 * discount div 100)" calculatedtrigger="onchange" label="Total" name="total"
 type="integer"/>

See also:

Personal tools