jnupponen
jnupponen

Reputation: 745

Splitting nested XML with Camel Tokenizer language

I am trying to split following XML with Camel's XMLTokenizer language:

<units>
    <unit type="menu">
        <id>1</id>
        <unit type="submenu">
            <id>1</id>
        </unit>
    </unit>
    <unit type="menu">
        <id>2</id>
        <unit type="submenu">
            <id>1</id>
        </unit>
    </unit>
</units>

My splitter looks like this:

.split().tokenizeXML("unit").streaming()

and my problem is that it is producing splitted XML without end tag like this:

<unit type="menu">
    <id>1</id>
    <unit type="submenu">
        <id>1</id>
    </unit>

It would appear that with tokenizeXML() it is not possible to get this working since it will just scan for </unit> end tag. What would be preferred way to handle this case? Is there some other splitting method that would get me the result that I need? I would like to use streaming() so splitting with xpath() is not an option for me.

Upvotes: 0

Views: 557

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55525

You can use camel-stax that allows to use the SAX api that supports streaming mode.

You would need to define a POJO and the JAXB annotations that declares the binding.

Upvotes: 1

Related Questions