neptune
neptune

Reputation: 1420

How to clean up an XML file for Java parsing by putting quotes around attributes

I have a series of xml files that looks something like this:

<ROOT>
    <F P=100> Some text here </F>
    <F P=101> More text </F>
    ...
</ROOT>

I'm trying to parse the xml using the standard DOM way, but because the attribute values for P are not in quotes, Java complains.

I tried using JTidy to clean it up, but because my xml isn't HTML, Tidy throws errors complaining that it doesn't recognize the tags <ROOT> and <F> etc.

So, is there another way to do this? Alternatively, I guess I could use regex since the only attributes without quotes occur in the <F> tags. Any thoughts on either?

Thanks in advance

Upvotes: 3

Views: 3053

Answers (1)

Qtax
Qtax

Reputation: 33918

All I had to do was set tidy.setXmlTags(true) so that tidy treats the input as XML and not HTML

– sheldon

Upvotes: 3

Related Questions