开发者

How to convert Not Valid Xml to valid Xml with special characters in element texts

开发者 https://www.devze.com 2023-03-04 12:24 出处:网络
Hi I have a not valid xml \"<samplexml> my text with & or < chars </samplexml>\" I want to convert it to a valid XML, replacing the special chars in text. So result will be:

Hi I have a not valid xml "<samplexml> my text with & or < chars </samplexml>"

I want to convert it to a valid XML, replacing the special chars in text. So result will be:

"<开发者_开发技巧samplexml> my text with &amp ; or &lt ; chars </samplexml>"

Do anyone knows some lib in Java that already solves this problem?

thx


Don't think of it as "not valid XML". Think of it as "not XML". If you're given some input text, you will have to write a parser for it. It's not XML, so you can't use an XML parser, you will have to write your own. Before you can do that, you need to define the syntax of the language that you want to parse. It wouldn't do any harm to do that by taking the grammar of XML, and using that as a basis for writing a grammar for the non-XML language that you want to accept.

0

精彩评论

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