开发者

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

开发者 https://www.devze.com 2023-03-05 20:30 出处:网络
I have a series of xml files that looks something like this: <ROOT> <F P=100> Some text here </F>

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


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

– sheldon

0

精彩评论

暂无评论...
验证码 换一张
取 消