Using Jodd Lagarto to parse XML

340 views Asked by At

I am using Jodd Lagarto to parse some HTMLs. For some cases I also use Jerry, when I need to quickly process HTML. But now, I have some XMLs that I need to process. From the TagVisitor it looks like Lagarto may process XMLs as well (that would be awesome for me), but... I am not quite sure on how to do this.

Did anyone used Jodd Lagarto to process XMLs and how?

1

There are 1 answers

1
igr On BEST ANSWER

Yes, it is possible to use Lagarto for XML. I admit this is not so clear in the documentation, but there is way to enable xml mode for parsing. Here is a short example how:

LagartoDOMBuilder lagartoDOMBuilder = new LagartoDOMBuilder();
lagartoDOMBuilder.enableXmlMode();
Document doc = lagartoDOMBuilder.parse(xmlContent);

That's all! Method enableXmlMode sets several flags to make Lagarto parsing XMLs.

Even more, you can even use Jerry for parsing XMLs, too! Here is how:

Jerry.JerryParser jerryParser = Jerry.jerry();
((LagartoDOMBuilder) jerryParser.getDOMBuilder()).enableXmlMode();
Jerry doc = jerryParser.parse(xmlContent);

Now you can use jQuery syntax and CSS selectors to filter your XML (aint that awesome, or what;)