XML->JDOM->String-> JAXP -> org.w3c.dom.Document
800344Oct 25 2007 — edited Oct 29 2007Hello,
I am using Strut2 to generate an XML file. To this end, I need a method to return a "org.w3c.dom.Document".
The data first comes from an XML file which contains some special caracters such as "&".
A third part program used JDOM to parse it. JDOM parser replace "&" by "&".
I iterated the JDOM Document and fetch all the data and constract a String for XML.
Trick!!! Now I replace "&" by "&" (without this it will not work)
Then I convert the String to byte[] then to ByteArrayInputStream.
Finally I used JAXP's DocumentBuilderFactory to parse the ByteArrayInputStream to get org.w3c.dom.Document.
By this way, it is fine.
!!!However, the data may contain other special characters. I can not just do replacing "&" by "&"
Do you see another way to solve the problem?
Thanks.
Pengyou