[jdom-interest] XML escaping and unescaping

Elliotte Harold elharo at metalab.unc.edu
Fri Nov 19 18:47:54 PST 2004

d.wall at computer.org wrote:

> Thanks.  I'll take a look at your escapers and compare.  It's a bit 
> amazing that such functionality isn't just part of the standard class 
> libraries by now.

It *is* part of the standard libraries. JDOM does this. XOM does it. DOM 
does it. Probably a dozen or so others do it.

> As for coming back in, an XML parser won't decode a string for you, will 
> it?  I mean, if my XML looks like:
> <data>
> <field>This &quot;is&quot; a test.</field>
> </data>
> I would expect that getting the data->field text value would return:
>      This &quot;is&quot; a test.
> Are you saying some XML parsers will return instead:
>      This "is" a test.

I'm saying *all* XML parsers will do this. If they don't do this they're 
not an XML parser. You're vastly overthinking the problem. You only need 
to worry about this stuff if you're rolling your own XML from scratch. 
If you're using a library, it is handled. If you're not using a library, 
well the library can't help you if you don't use it. You might want to 
check out Effective XML. This specific issue is addressed in Item 9.

Elliotte Rusty Harold  elharo at metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!

More information about the jdom-interest mailing list