f



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

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
0
purzel30 (13)
7/28/2004 7:26:17 AM
comp.text.xml 8781 articles. 0 followers. Post Follow

1 Replies
510 Views

Similar Articles

[PageSpeed] 42

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    |
  -----------------------
0
7/28/2004 7:52:22 AM
Reply: