[jdom-interest] Preventing Escape Character Conversion

Stephan Trebels stephan at ncube.de
Thu Mar 27 03:25:53 PST 2003


In short, what you request is not possible.  You will be able to do what
you probably want, though.

JDOM will faithfully represent the "parsed" XML which is a "Hello
&World" according to the XML spec.  This string contains an ampersand,
not an entity of course.   When you output this XML, it will be
converted to Hello &World again, therefore it shouldn't make any
difference.

If you really want to know whether there is a & in the input, you'll
have to go down to the SAX parser level.  When JDOM gets involved it's
too late already.

Stephan

On Thu, 2003-03-27 at 13:19, Ian Bryson wrote:
> Hi,
> 
> I need to prevent escape characters being converted when I read in an XML 
> string.  I have & in my XML and I don't want them being converted to &.
> 
> I am doing something like the following:
> 
>     SAXBuilder builder = new SAXBuilder();
>     StringReader s = new StringReader("<hello><world>Hello &amp; 
> World</world></hello>");
>     Document doc = builder.build(s);
> 
>     Element e = doc.getRootElement();
>     Element wrld = e.getChild("world");
>     System.out.println(wrld.getText);
> 
> This converts &amp; to &.
> 
> Any help in preventing this conversion would be appreciated.
> 
> Cheers,
> 
> Ian
> 
> 
> 
> _________________________________________________________________
> Worried what your kids see online? Protect them better with MSN 8 
> http://join.msn.com/?page=features/parental&pgmarket=en-gb&XAPID=186&DI=1059
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
-- 
        Stephan Trebels <stephan at ncube.de>   Consultant
company: nCUBE Deutschland GmbH, Hanauer Str. 56, 80992 Munich, Germany
phone: cell:+49 172 8433111  office:+49 89 1498930  fax:+49 89 14989350





More information about the jdom-interest mailing list