Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML->JDOM->String-> JAXP -> org.w3c.dom.Document

800344Oct 25 2007 — edited Oct 29 2007
Hello,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 26 2007
Added on Oct 25 2007
5 comments
449 views