XML

From SoftIVR

Jump to: navigation, search

XML functions

SoftIVR provides inbuilt functions to parse and extract data from XML documents. Each call has internal storage for one XML document, which can be loaded and parsed using the parseXML and getXPath functions.

Here's an example XML document:

<weather>
  <location>London</location>
  <temperature>
    <temp>17</temp>
    <units>centigrade</units>
  </temperature>
</weather>

Assuming that this is in the variable xml, which might (for example) be the result of a web page fetch, we can parse this XML in to an internal structure using

parseXML(xml);

and then extract items from it as follows:

location = getXPath("/location");
temp = getXPath("/temperature/temp");
units = getXPath("/temperature/units");

and then, finally, tell the user:

say("The temperature in " + location + " is " + temp " + " " + units + ".");