By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 3,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 Schmidbauer wrote:
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

--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.