Interacting with XML-based web services using SPARQLMotion
One of the new features of TopBraid 3.0 is improved handling of web services that return XML results. We have added two new module types to SPARQLMotion that can be used to walk through XML documents via XPath. Here is an illustrated example of how to use these capabilities. You can also download and play with the example script.
The first step is a web service call using sml:ImportXMLFromWorkspace:
In order to do that, we want to walk through all code tags of the XML result. We add an sml:IterateOverXPath module that takes the ?xml from the previous step as input:
At this stage, Composer offers a convenience feature: right click on the IterateOverXPath module and select "Set XPath...": this will execute the script up to that module and open up an XPath creation dialog. This dialog can be used to select the path to the elements that we want to iterate over:
After we have defined and assigned the XPath, we can now specify what we want to do with each code element from the XML document. In order to do so, we create the body of the iteration module as shown in the overview below. This body will be repeated for each code element. The ?xml variable is then bound to the current code element as root.Each of the three sml:BindByXPath modules has a local XPath starting at the respective code element. Again, we can use the "Set XPath..." feature to let the SPARQLMotion engine execute up to the module and open an XPath editor dialog:
We simply need to pick the example instance data (here, the specific latitude value) and the dialog will generalize it into an XPath expression in the text field. This will bind the specified text node to the variables ?name, ?lat and ?long. In the final step, we define a SPARQL Construct query using sml:ApplyConstruct to create RDF triples for those values:
0 Comments:
Post a Comment
<< Home