In camel 2.14.0, there is an xml-aware tokenizer that can solve your problem.
http://camel.apache.org/splitter.html
In an older system, you need to come up with your own custom solution.
But in general, when using an xml-parser to process a non-wellformed
xml documents, it probably doesn't make much sense to partially
process the document. Suppose you have the input
<data>
<record>
<account pan="12345"></account>
/record>
record>
<account pan="67891"></account>
</record>
<record>
account pan="98657">/account>
</record>
</data>
Which entries do you want to process or accept? The xml parser will
report two tokens without throwing any errors although the document
appears completely corrupt but yet empirically one can assume there
are three account values, which could have been successfully extracted
if you were using a custom text-based extractor.
regards, aki
2014-09-17 15:07 GMT+02:00 balavino <[email protected]>:
> Hi,
>
> I don't have a xsd schema to validate the xml file. I only need to make sure
> that there is no malformation in the whole xml, in that case if the xml is
> malformed i have a option to stop from futher processing in the route. Do
> you have any ideas to do this?
>
> *xml-file:*
> /<data>
> <record>
> <account pan="12345"></account>
> </record>
> <record>
> <account pan="67891"></account>
> </record>
> </data>/
>
> *route xml:*
>
> / <split strategyRef="splitXmlAggregator"
> stopOnException="true">
> <tokenize token="record" xml="true" />
> <setHeader headerName="Id">
> <xpath
> resultType="java.lang.String">/record/account@pan</xpath>
> </setHeader>
> </split>/
>
> I use tokenizer to split based on xml file based on the token "record" into
> 2 splits. If i have a malformation inside the level of <record> tag the the
> javax.xml.XPathExpressionException is thrown.
>
> When i do have a malformation as below:
>
> /<data>
> <record>
> <account pan="12345"></account>
> </record>
> record>
> <account pan="67891"></account>
> </record>
> </data>/
>
> Where the second record tag doesn't have a start '<' delimiter i.e on the
> level of the <record> tag then the number of splits i get is only 1 not 2. I
> wish to atleast log that i have skipped a record from being processed, a
> count of the no. of records skipped. The second option is atleast i get to
> log the skipped record, any suggestions for this?
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-split-tokenizer-does-not-identify-malformed-xml-tp5756111p5756638.html
> Sent from the Camel - Users mailing list archive at Nabble.com.