| CallXML 3.0 Development Guide | Home | Frameset Home |
|
<assign var="child" expr="list(//disc[1]/child::*/text())"/>
<?xml version="1.0" encoding="UTF-8"?>
<callxml version="3.0">
<!-- fetch our XML document, and assign it to a locally scoped CallXML variable -->
<fetch value="AdvancedAddress.xml" var="myFetch" type="xml"/>
<block label="Addressing" value="$myFetch;">
<log>*** select the first 'addy' element that is a child of the 'addresses' element:</log>
<assign var="address1" expr="/var/myFetch/addresses/addy[1]/text()"/>
<log>*** ADDRESS 1: $address1; ***</log>
<wait value="1s"/>
<assign var="address2" expr="/var/myFetch/addresses/addy[last()]/text()"/>
<log>*** select the last 'addy' element that is a child of 'addresses':</log>
<log>*** ADDRESS 2: $address2; ***</log>
<wait value="1s"/>
<assign var="address3" expr="/var/myFetch/addresses/addy[last()-1]/text()"/>
<log>*** select the next to last 'addy' element that is a child of 'addresses':</log>
<log>*** ADDRESS 3: $address3; ***</log>
<wait value="1s"/>
<assign var="address4" expr="list(/var/myFetch//addresses/addy[position()<4]/text())"/>
<log>*** select the first three 'addy' elements that are children of 'addresses':</log>
<!-- note that we need to call the 'list' function to output this array of values -->
<log>*** ADDRESS 4: $address4; ***</log>
<wait value="1s"/>
<assign var="address5" expr="list(//addy[@state]/text())"/>
<log>*** select all 'addy' elements that have a 'state' attribute defined:</log>
<!-- again, we need to call the 'list' function to output the array of values -->
<log>*** ADDRESS 5: $address5; ***</log>
<wait value="1s"/>
<assign var="address6" expr="list(//addy[@state='California']/text())"/>
<log>*** select all 'addy' elements that have an attribute named 'state', and have a value of 'California':</log>
<log>*** ADDRESS 6: $address6; ***</log>
<wait value="1s"/>
<assign var="address7" expr="list(//addy[@val>22.3]/text())"/>
<log>*** select all 'addy' elements that have a 'val' attribute whose value is greater than '22.3':</log>
<log>*** ADDRESS 7: $address7; ***</log>
<wait value="1s"/>
<assign var="address10" expr="list(//*)"/>
<log>*** select all elements in the document:</log>
<log>*** ADDRESS 10: $address10; ***</log>
<wait value="1s"/>
<assign var="address11" expr="list(//addy[@*]/text())"/>
<log>*** select all 'addy' elements that have an attribute of any kind:</log>
<log>*** ADDRESS 11: $address11; ***</log>
<wait value="1s"/>
<assign var="address12" expr="list(//addy[@state='California']/text() | //addy[@state='Florida']/text())"/>
<log>*** all 'addy' elements that have attributes named 'state' and have a values of 'California' AND attributes that have values of 'Florida'</log>
<!-- illustrates using the '|' (AND) operator to select two paths: -->
<log>*** ADDRESS 12: $address12; ***</log>
<wait value="1s"/>
</block>
</callxml>
<?xml version="1.0" encoding="UTF-8"?>
<mynodes>
<addresses>
<addy state="Florida" val="11.1"> 111 pine street </addy>
<addy state="Georgia" val="22.2"> 222 saint andrews boulevard </addy>
<addy state="California" val="33.3"> 333 twin lakes drive </addy>
<addy val="44.4"> 444 masters boulevard </addy>
<addy state="New York" val="55.5"> 555 bimini lane <crime level="high">higher</crime> </addy>
<addy state="Montana" val="55.5"> 666 goodrich lane </addy>
<addy> 777 happyjack street</addy>
</addresses>
</mynodes>
| ANNOTATIONS: EXISTING POSTS |
moshe
|
|
| I'm confused as to how the "fetch" attribute "var" becomes associated with the particular XML nodes I'm trying to read.
In this example, I see the fully-qualified path name of "/var/myFetch/addresses" to find the addresses node inside the myFetch var. I also see "//addr" as a path to the nodes; presumably this works because of the block statement's attribute of "value" being set to myFetch. So are these two alternative formulations equivalent? |
|
moshe
|
|
| How to use assign:
To use xpath with assign, the following three attributes must be given: var -- name of the variable value - the variable that contains the xpath read in via fetch expr - the xpath expression |
| login |
|