|
XPathQueryProcess Element |
|
|
XPathQueryProcess is used to query an XML string or a pre-parsed Node with the specified XPath expression. Since it is a "QueryProcess", sub processes can be configured under it so that they can be executed for each matched XML node.
Properties Xml Input (Accepts MScript) Either an XML string or a pre-parsed Node. An XML string can be parsed with MScript function parsexml(). Encoding (Accepts MScript) The character encoding of the XML input. The default value is "UTF-8". XPath Expression (Accepts MScript) A XPath expression to query the nodes of the xml. The definition should return a node set NOT a string or a boolean. Output Fields (Accepts MScript) This property the output fields and their mappings to the XML nodes or to the attributes. The definitions should be separated with a comma. The syntax of a definition is as follows: field-name: relative-xpath-expression
field-name The name of the output field.
relative-xpath-expression The XPath expression can be defined relative to the matched nodes and it may return a string value or a Node. To map a output field to a Node a "*" must be appended at the end of the field name.
Example:
XML Input: <root> <order> <customerId>188</customerId> <orderDate>2009-05-25</orderDate> <product id="7899" qty="100" price="35" /> </order> <order> <customerId>200</customerId> <orderDate>2009-08-11</orderDate> <product id="09182" qty="10" price="1200" /> <product id="FD541" qty="3" price="450" /> <product id="P0912" qty="50" price="100" /> </order> </root>
XPath Expression:
Output Fields: STATUS: orderDate, PRODCNT: count(product), PRODS*: product Note that output field "PRODS" will contain a Node object which means it can be queried by another XPathQueryProcess that is configured as a sub process or by a xpath() MScript function. Using namespace prefix in XPath Expression and Output Fields
XML Input: <cns:customer id="1" xmlns:cns="http://www.localhost.com/customer"> <ons:order xmlns:ons="http://www.localhost.com/order"> <ons:orderNumber>21354</ons:orderNumber> </ons:order> </cns:customer> <cns2:customer id="2" xmlns:cns2="http://www.localhost.com/customer2"> <ons:order xmlns:ons="http://www.localhost.com/order"> <ons:orderNumber>74544</ons:orderNumber> </ons:order> </cns2:customer> </root>
XPath Expression: ONUM: ons:orderNumber
If an XPath expression contains a namespace prefix then the XML data will be parsed into DOM as "namespace aware" in order the XPath expression to work. Ignoring namespace prefix Even if your XML data contains namespaces you can still have an XPath expression without prefixes. In that case the XML will be parsed without namespaces and your XPath will work again as in the case below.
XPath Expression: ONUM: orderNumber
Default Namespace If a namespace is defined on a node and there is no namespace prefix used for it (the default namespace) then to address the nodes that use the default namespace ":" prefix should be used.
XML Input: <root> <cns:customer xmlns:cns="http://www.localhost.com/customer"> <order xmlns="http://www.localhost.com/order"> <orderNumber>21354</orderNumber> </order> </cns:customer> <cns2:customer xmlns:cns2="http://www.localhost.com/customer2"> <order xmlns="http://www.localhost.com/order"> <orderNumber>21354</orderNumber> </order> </cns2:customer> </root>
XPath Expression: ONUM: ./:orderNumber
Please note that how "./" characters used in front of :orderNumber. Since an XPath expression cannot start with ":" character, "./" characters were inserted in front of it.
|