XML problem with special characters like "<" and ">"

Christian Schmidbauer

Usenet Archive
Joined
Jul 28, 2004
Messages
3
Reaction score
0
Hello!

I prepare my XML document like this way:

PrintWriter writer;
Document domDocument;
Element domElement;

// Root tag
domElement = domDocument.createElement ("ROOT_TAG");
domDocument.appendChild (domElement);

// XML from an external source as a "String"
Text data = domDocument.createTextNode (externalXML);
domElement.appendChild (data);

writer.println (...);

As you can see, I create a normal Root-Node and then I get an XML stream from an external source. For the external XML I use the function "createTextNode" because it is a text in some way.

The problem is the output when I write all together to the PrintWriter object. It looks like this for this example:

<?xml version="1.0" encoding="UTF-8"?>

<ROOT_TAG>

&lt;DATA&gt;
&lt;AFL&gt;
&lt;AFLNR&gt;XX&lt;/AFLNR&gt;
&lt;BENENNUNG&gt;MY TEST&lt;/BENENNUNG&gt;
&lt;LA_VER&gt;&lt;/LA_VER&gt;
&lt;FA_KR&gt;&lt;/FA_KR&gt;
&lt;POL_COD&gt;&lt;/POL_COD&gt;
&lt;FA_KZ&gt;&lt;/FA_KZ&gt;
&lt;G_KZ&gt;&lt;/G_KZ&gt;
&lt;AFL_KZ&gt;1&lt;/AFL_KZ&gt;
&lt;/AFL&gt;
&lt;/DATA&gt;
</ROOT_TAG>

Strange, isn't it!? The sign "<" is being replaced by "&lt;" and ">" is being replaced by "&gt;", but only for the XML coming from the external source.

Does anybody know this problem or can think about a solution? Should I use another function than "createTextNode" or do I have to change the special characters manually?

Thank you for every hint!

Best regards,
Christian Schmidbauer
 

Philippe Poulard

Usenet Archive
Joined
Dec 20, 2001
Messages
412
Reaction score
0
hi,

< is used to introduce markups
&lt; is used for the text < (it's a way to escape this character)

so, if you want to have markups, you mustn't append text node : try instead to parse your external xml to an xml document, import its root element in your host document, and append it

Christian said:
Hello!

I prepare my XML document like this way:

PrintWriter writer;
Document domDocument;
Element domElement;

// Root tag
domElement = domDocument.createElement ("ROOT_TAG");
domDocument.appendChild (domElement);

// XML from an external source as a "String"
Text data = domDocument.createTextNode (externalXML);
domElement.appendChild (data);

writer.println (...);

As you can see, I create a normal Root-Node and then I get an XML stream from an external source. For the external XML I use the function "createTextNode" because it is a text in some way.

The problem is the output when I write all together to the PrintWriter object. It looks like this for this example:

<?xml version="1.0" encoding="UTF-8"?>

<ROOT_TAG>

&lt;DATA&gt;
&lt;AFL&gt;
&lt;AFLNR&gt;XX&lt;/AFLNR&gt;
&lt;BENENNUNG&gt;MY TEST&lt;/BENENNUNG&gt;
&lt;LA_VER&gt;&lt;/LA_VER&gt;
&lt;FA_KR&gt;&lt;/FA_KR&gt;
&lt;POL_COD&gt;&lt;/POL_COD&gt;
&lt;FA_KZ&gt;&lt;/FA_KZ&gt;
&lt;G_KZ&gt;&lt;/G_KZ&gt;
&lt;AFL_KZ&gt;1&lt;/AFL_KZ&gt;
&lt;/AFL&gt;
&lt;/DATA&gt;
</ROOT_TAG>

Strange, isn't it!? The sign "<" is being replaced by "&lt;" and ">" is being replaced by "&gt;", but only for the XML coming from the external source.

Does anybody know this problem or can think about a solution? Should I use another function than "createTextNode" or do I have to change the special characters manually?

Thank you for every hint!

Best regards,
Christian Schmidbauer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top