user3313941
user3313941

Reputation: 63

Escape \ in XML?

In C# code, I've used the below format for Date Time in .ToString() method.

Format= "\"'\"yyyy-MM-dd HH:mm:ss.fff\"'\"" 

this format also appends quotes to the formatted date time in string and works well when used in csharp.

However, I want to pass this format in an XML file but serialization fails because of \.

How to escape \"'\" in format ?

Upvotes: 1

Views: 67

Answers (1)

kjhughes
kjhughes

Reputation: 111621

Backslash (\) is not an escape prefix character in XML:

  • \ itself does not need to be escaped in XML character data.

  • \ itself is not allowed to appear in XML component (element or attribute) names.

To escape:

  • & use &
  • " use "
  • ' use '
  • < use &lt;
  • > use &gt;

But be sure to take context into account: XML character escaping requirements are context sensitive.

Upvotes: 2

Related Questions