: [XML-SIG] "&" and "<" within a string

Thomas B. Passin tpassin@idsonline.com
Thu, 15 Jul 1999 08:22:08 -0400

On Tuesday, 13 July, wasc wrote:

>Subject: [XML-SIG] "&"  and "<" within a string
>saxlib is throwing exceptions when I use "&" and "<" literally within an
>attribute value of type string, as it should.
>For example,
> <tag> name= "R&D library" value="<ROOT>/lib" />
>The XML spec says to use "&amp;" and "&lt;" when used literally in string.
>However, if I define
> <tag> name= "R&amp;D library" value="&lt;ROOT>/lib" />
>I still get an exception (apparently, the parser accepts the ">" and "/").
>Am I interpreting the spec correctly? Any suggestions?

Your problem is ill-formed XML, if your sample code is accurate.  The following version works fine (meaning that it gets accepted by
the msxml parser, and by xt if you have an acceptable stylesheet):

<?xml version="1.0"?>
<tag name="R&amp;D library" value="&lt;ROOT>/lib" />

Here is a stylesheet for the above xml that works with xt:

<?xml version="1.0"?>

<xsl:template match="tag">
 name: <xsl:value-of select="@name"/>
 value: <xsl:value-of select="@value"/>


Here is the xt output:

C:>xt x1.xml x1.xsl

        name: R&amp;D library
        value: &lt;ROOT&gt;/lib

Thomas Passin