XPath splitter

XPath splitter

The XPath splitter is a service which can split XML input content into multiple parts based on an XPath definition. The results of the service are multiple output messages with the result of the XPath split on the configured MessagePart. The format of the input MessagePart has to be string or document. The format of the result MessagePart depends on the input format.

In the table below, you will find an explanation of these properties. All attributes with a ‘*’ are mandatory.

Attribute

Description

Name*

By default, we fill this out with the technical ‘tag’, followed by a serial number. Changing the name is optional.

Enabled

Set this value to true, if you want this service to be enabled.

XPath Expression*

Expression to use to split the XML. Should result in a nodeset.

MessagePart

Name of the MessagePart in a ConnectMessage where the content of the file is being stored.

Description

Description of the specific service. This is for documentation purposes.

When you select the  behind the field XPath Expression, you will enter an XPath Tester program.

You can enter an XPATH expression and an XML example. When you press the  button the expression will be performed on the given XMl File. The result will be returned in the result field.

(I.E.: If your XML uses namespaces, the tester will return an answer, but the XPATH Splitter will not! See => XML file with namespaces)

Example

Use the following .XML file as XML Example:

<?xml version="1.0" encoding="UTF-8"?>

<bookstore>

<book category="cooking">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="children">
  <title lang="en">Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

<book category="web">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>

<book category="web">
  <title lang="en">Learning XML</title>
  <author>Erik T. Ray</author>
  <year>2003</year>
  <price>39.95</price>
</book>

</bookstore>

Now use the following XPATH expressions and check the results:

XPATH Expression Result
/bookstore/book[1]/title
/bookstore/book[1]/title/text()
/bookstore/book[price>35]/title

CDATA Values

If you work with CDATA tags in your XML, after splitting the XML up into seperate parts, the CDATA tag will be removed from your new XML message. All special characters will be correctly escaped during this process.

For instance, the & character will be replaced by &amp.

XML file with namespaces

If your XML file of messagepart has namespaces, you cannot use the above syntax for the XPATH Splitter. You have to use a specific syntax to deal with this.

You can detect namespaces whan the XMLNS property is used in the tag.

<Messages
    xmlns="http://www.connectplaza.com/generic-consignment"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          version="1.00"
          xsi:schemaLocation="http://www.connectplaza.cm.com/generic-consignment file:///A:/Projects/Order/Schemas/Customer/CP_Consumption.xsd">

If you want alle message from messages, you normally type: /Messages/* or /Message/message. But in this case you need the localname variant:

//*[local-name()='Message']