|
<< Click to Display Table of Contents >> Navigation: Components > Communication > Multi-IO-IP > Filter > XML Filter |
XML filter (only on strings)
The XML filter expects an XML document, for example, in response to an XML Web service. The individual fields of the data filter editor are explained below.
The filter expression is shown by way of example in the following. Only the XPath expression has to be entered (see examples at the end of this chapter). The syntax of the path specification corresponds to the XML Path Language (XPath). XPath is a request language developed by the W3 consortium to address parts of an XML document. The addressed node must be a sheet, that is, no element type and must have a convertible text as a value. A path to an "end node" is specified in XPath over the individual tag names separated by a "/". If you want to address tags with attributes and concrete attribute values, these are specified in brackets after a tag name. At the end of this chapter are a few examples that illustrate the use of XPath.
example
Xml Document:
<? Xml version = "1.0" encoding = "utf-8"?>
<Dok>
<! - an XML document ->
<Tag1> testtext </ tag1>
<Kap title = "Nice document">
<Pa> A paragraph </ pa>
<Pa> Another paragraph </ pa>
<Pa> And another paragraph </ pa>
<Pa> Nice, is not it? </ Pa>
</ Cape>
<Kap title = "Second Chapter">
<Pa> 3 </ pa>
</ Cape>
<Kap title = "Second Chapter">
<Pa> 3 </ pa>
</ Cape>
<Tag2 attr2 = "attr2 value" attr2 = "attr2 value">
<Value> Example value </ value>
</ Tag2>
</ Dok>
XPath path example 1
/ Dok / tag1
This XPath string extracts the value "testtext" from the XML document.
XPath path example 2
/ Dok / kap [@ kap = "Second chapter"] / pa
This XPath string extracts the value 3 from the XML document. If a tag has more than one attribute, it can also be specified in the XPath string using the identifier "and":
/ Dok / tag2 [@ attr1 = "attr valuel" and attr2 = "attr2 value"] / value
Returns the text "Example value".
For more detailed information, please see documentation for XPath. The following link provides a fairly compact and sufficient tutorial on XPath:
XPath Path Example 3 (Determine Attribute Values)
To read out the value of the attribute "attr1" from the above example of <tag2>, the following expression is used:
Expression: / dok / tag2 / @ attr1
Return value: "attrvalue"
XPath path example 4
If a document contains multiple nodes with the same tag name, the correct one can be determined using an index. In the above example, there are several nodes with the name kap.
The following expression returns the value of the title attribute of the 3rd node as seen from the beginning of the document, which has the tag name cape
Expression: / dok / cape [3] / @ attr1
Return value: "third chapter"
http://www.w3schools.com/xpath/default.asp