Discussion:
Special characters problem while writing XML files using JAXP DOM Parser
nagineni
2009-12-04 05:25:08 UTC
Permalink
Hi,

I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
<name>naga</name>
<expr>for(int i=0;i&lt20;i++)</expr>
</template>

I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.

Regards,
Naga.


-----
Regards,
Naga.
--
View this message in context: http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
Mukul Gandhi
2009-12-04 05:40:21 UTC
Permalink
it seems, you are not writing the built in entity reference for
character, "<" appropriately.
you are not writing a semicolon, after &lt.

The parsing of the document you have posted, would likely fail with
this particular error.

The Xerces-J sax.Counter sample gives following error, while parsing
the XML document you have posted:

[Fatal Error] test.xml:4:35: The entity "lt20" was referenced, but not declared.
Post by nagineni
Hi,
I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
         <name>naga</name>
         <expr>for(int i=0;i&lt20;i++)</expr>
</template>
I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.
Regards,
Naga.
--
Regards,
Mukul Gandhi
Benson Margulies
2009-12-04 12:13:06 UTC
Permalink
If you need a less than, you need to put it all in a CDATA.
Post by nagineni
Hi,
I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
         <name>naga</name>
         <expr>for(int i=0;i&lt20;i++)</expr>
</template>
I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.
Regards,
Naga.
-----
Regards,
Naga.
--
View this message in context: http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
Michael Glavassevich
2009-12-04 13:23:58 UTC
Permalink
Sure, lexically but CDATA is just syntactic sugar. An entity reference
(&lt;) or character reference (&#60; or &#x3C;) would also work fine.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Post by Benson Margulies
If you need a less than, you need to put it all in a CDATA.
Post by nagineni
Hi,
I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
         <name>naga</name>
         <expr>for(int i=0;i&lt20;i++)</expr>
</template>
I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.
Regards,
Naga.
-----
Regards,
Naga.
--
View this message in context: http://old.nabble.com/Special-
characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-
tp26635769p26635769.html
Post by nagineni
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
Benson Margulies
2009-12-04 15:53:29 UTC
Permalink
I (mis?)understood the original poster to have a strong opinion on the
lexical surface form of the XML.

On Fri, Dec 4, 2009 at 8:23 AM, Michael Glavassevich
Post by Michael Glavassevich
Sure, lexically but CDATA is just syntactic sugar. An entity reference
(&lt;) or character reference (&#60; or &#x3C;) would also work fine.
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
Post by Benson Margulies
If you need a less than, you need to put it all in a CDATA.
Post by nagineni
Hi,
I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
         <name>naga</name>
         <expr>for(int i=0;i&lt20;i++)</expr>
</template>
I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.
Regards,
Naga.
-----
Regards,
Naga.
--
View this message in context: http://old.nabble.com/Special-
characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-
tp26635769p26635769.html
Post by nagineni
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
k***@us.ibm.com
2009-12-04 13:29:53 UTC
Permalink
Or, better, escape the individual troublesome character by expressing it
as &lt;

XML also considers > and & to be reserved characters; they should be
expressed as &gt; and &amp;.

<[[CDATA[]]> sections, which provide a block-escaping mechanism, are
sometimes useful for hand-generated XML; less so for machine-generated. I
generally discourage their use.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
-- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (
http://www.ovff.org/pegasus/songs/threes-rev-11.html)



Benson Margulies <***@gmail.com>
12/04/2009 07:13 AM
Please respond to
j-***@xerces.apache.org


To
j-***@xerces.apache.org
cc

Subject
Re: Special characters problem while writing XML files using JAXP DOM
Parser






If you need a less than, you need to put it all in a CDATA.
Post by nagineni
Hi,
I'm creating xml file using JAXP DOM parser.While writing text data to a
node parser is writing special characters.Below is the example.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<template>
<name>naga</name>
<expr>for(int i=0;i&lt20;i++)</expr>
</template>
I want to my XML file output for(int i=0;i<20;i++) inside <expr> element.Is
there any solution around it ?
Can any one suggest me the solution for this problem ?Thanks in advance.
Regards,
Naga.
-----
Regards,
Naga.
--
http://old.nabble.com/Special-characters-problem-while-writing-XML-files-using-JAXP-DOM-Parser-tp26635769p26635769.html
Post by nagineni
Sent from the Xerces - J - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-***@xerces.apache.org
For additional commands, e-mail: j-users-***@xerces.apache.org
Loading...