TidyMarkup

The TidyMarkup (or TagSoup) component is used to parse malformed XML and should only be used in that case. When XML is properly formatted see How to process XML. Learn how to work with the TidyMarkup component.

Library

Create a new library with the following jars (in this order):

Camel version Library jars
2.18.3

See How to retrieve the Camel version of Decision Insight.

Routes

Now it's possible to create a route that uses this component. For the example we need to try to parse this XML file:

 <products>
    <product>
        <id>id1
        <name>name of id1
    <product>
        <id>id2
        <name>name of id2
    </product>
</products>

As you can see there is many missing closing tag. See the TagSoup website in order to see which kind of correction is done by the library.

Here the definition of the route:

<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns:u="http://www.systar.com/aluminium/camel-util" xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="direct:inject"/>
        <unmarshal>
            <tidyMarkup/>
        </unmarshal>
        <split>
            <xpath>//product</xpath>
            <setBody>
                <xpath resultType="java.lang.String">/product/id/text()</xpath>
            </setBody>
            <to uri="log:tidy-test"/>
        </split>
    </route>
</routes>

This route should log the ids of the products by using the xpath expression.

Related Links