Sam
Sam

Reputation: 129

How to Show & in xml constructed from string

I am creating a web api using asp.net mvc4 and the response output is xml. Before outuptting to browser I modify the xml response so that one of the values between the start and closing tags contain a url string which may have '&' When outputting in browser, this generates an error that xml is not well formed. I have read from How to show & in a XML attribute That would be produced by XSLT that one can use D-O-E to generate unescaped content using xslt but dont know how this could apply for xml generated from a string and displayed in browser

Upvotes: 2

Views: 1364

Answers (1)

Kevin Main
Kevin Main

Reputation: 2344

You should encode the & as

& 

which is understood by XML (see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined%5Fentities%5Fin%5FXML)

Another alternative would be to surround the output in a CDATA tag (http://stackoverflow.com/questions/2784183/what-does-cdata-in-xml-mean)

Upvotes: 2

Related Questions