views:

2177

answers:

5

How do I escape ampersands (&) in XML - I tried & but this isn't allowed.

OK The question was poor, I wanted to escape it in such a way that it was rendered as & in the web page that used the XML output. So I had to do add an additional amp; to my output.

+14  A: 

As per §2.4 of the XML 1.0 spec, you should be able to use &.

I tried & but this isn't allowed.

Are you sure it isn't a different issue? XML explicitly defines this as the way to escape ampersands.

John Feminella
+4  A: 

& should work just fine, Wikipedia has a List of predefined entities in XML.

nikc
+1  A: 

CDATA tags?

     <![CDATA[
       This is some text with ampersands & other funny characters. >>
     ]]>
scragar
This is a guess rather than an answer.
Bryan Oakley
It might be a guess; it is correct though. CDATA markers allow raw ampersands to be used.
David Dorward
scragar
A: 

&amp; is the only thing i know of

knittl
+4  A: 

&amp;amp; will result in &amp; when rendered. Which will result in & if rendered again...

Actually, I had a minor issue to provide this example since this site rendered the first amp; so only one was visible. To fix that, I had to use amp; three times after the &. Every amp; adds another render layer.

Workshop Alex