• 0

How do I output a backslash \ character in XML?


Question

4 answers to this question

Recommended Posts

  • 0

If it is an attribute, then it will just work, but I'm assuming you're trying to put it as text between tags:

<someXml>\a path\to\a\file</someXml>

In that case, you need to use a CDATA section.

<someXml>
<![CDATA[
	  \a path\to\a\file
   ]]>
</someXml>

  • 0
  $phinX said:

Ive found a couple of articles saying use: \ but that still errors.

LoL, just noticed that didnt come out... or it did... that backslash is actually a '&' followed by hex number, which obviously works for HTML but not XML.

  weenur said:

If it is an attribute, then it will just work, but I'm assuming you're trying to put it as text between tags:

Yeah im trying to up it between tags as text. Is CDATA the only way? There is no escape character sequence?

  • 0
  $phinX said:

LoL, just noticed that didnt come out... or it did... that backslash is actually a '&' followed by hex number, which obviously works for HTML but not XML.

Yeah im trying to up it between tags as text. Is CDATA the only way? There is no escape character sequence?

Wasn't really thinking, but you should be able to use the ASCII code equivalent.

& #92;

Gah! This is actually rendering the \ . lol It's ampersand, pound, ninety-two, and semicolon.

You may want to try using HttpServerUtility.HtmlEncode if you want to encode on the fly before you insert into a node's value.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.