472,804 Members | 778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,804 software developers and data experts.

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
Jul 20 '05 #1
1 6712
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lecichy | last post by:
Hello. Well, I found this piece of code on php.net. Thats fine but where can i find explanation for all these ("|\')?(*)("|\')?.*>(*)' syntax so that I can construct my own rules for all kind...
9
by: Francesco Moi | last post by:
Hello. I'm trying to build a RSS feed for my website. It starts: ----------------//--------------------- <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
8
by: active | last post by:
I use quickwatch on (astrThisOne <> "") and it reports: False as it should because astrThisOne reports: "" Yet If (astrThisOne <> "") Then executes the Then clause
4
by: Jon | last post by:
Hi, I used XslCompiledTransform with the following Xsl file. The <xsl:text disable-output-escaping="yes"does not work when using XslCompiledTransform to do the trnasform (namely the output...
3
by: Steven.Xu | last post by:
hi everybody, i am useing some classes which in System.Xml to deal with xml document. what can i do if the document include "<" or ">"? Thanks.
2
by: alxasa | last post by:
Hello, I am hoping someone can help me with this. I need a javascript function, which sits inside a <input type="text" name="firstname"> line of code. Now, if someone starts typing fine, but when...
11
by: Holger | last post by:
Hi I have not been able to figure out how to do compound statement from C - "<test>?<true-val>:<false-val>" But something similar must exist...?! I would like to do the equivalent if python...
36
by: Roedy Green | last post by:
The only browser I have encountered that supports <colgroup><col class="behold"></colgroup> to apply a CSS style to a whole column, is Microsoft Internet Explorer. I have been told it SHOULD NOT...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.