The forward slash is valid as is and does not need further encoding.

The only reserved characters are:

>
<
&
%

For even more XML entities - http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Answer from Ray Booysen on Stack Overflow
🌐
Coderanch
coderanch.com › t › 126304 › languages › slash-reserverd-character
Is forward slash / a reserverd character? (XML forum at Coderanch)
In case someone is interested, here are some examples of how you post stuff with special characters etc: UBB blocks: [CODE]foobar[/CODE] is written as &#91;CODE&#93;foobar&#91;/CODE&#93; XML/HTML snippets: <xml version="1.0"?> is written as &lt;xml version="1.0"?&gt;
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-escape-characters-in-xml
How to Escape Characters in XML ? - GeeksforGeeks
July 23, 2025 - In this approach, we are using the replace() method with a regular expression to search for characters <, >, ", ', and & in the XML data and replace them with their respective XML entities (&lt;, &gt;, &quot;, &apos;, &amp;). Example: The below example uses the replace() method to escape characters in XML.
🌐
Plan
saxonica.plan.io › issues › 6190
Support #6190: Forward slash escaped when using xml-to-json function - Saxon - Saxonica Developer Community - Saxon - Saxonica Developer Community - Saxon - Saxonica Developer Community
As a workaround, where you do xml-to-json($json), you can use xml-to-json($json) => parse-json() => serialize(map{ 'method' : 'json', 'use-character-maps' : map { '/' : '/' } }) instead. Kind of convoluted and I am only suggesting that as a possible workaround if you want a JSON output without the solidus/forwards slash being escaped,to move on with your code.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › desktop › xaml-services › xml-character-entities
XML Character Entities and XAML - XAML | Microsoft Learn
December 16, 2025 - XAML uses character entities defined in XML for special characters. This topic describes some specific character entities and general considerations for other XML concepts in XAML. XAML markup typically uses the same character entities and escape sequences that are defined in XML.
🌐
UNL
cse.unl.edu › ~reich › XML › syntax.html
XML syntax is similar to HTML.
Inside the tag delimiters, start-tags ... element type name and end with a '/' (forward slash). The example in the textbook illustrates all three types of tags, e.g., start-tag "<HEAD>", end-tag "</HEAD>", and empty-tag "<BR/>". XML requires proper nesting....
🌐
SAP Community
community.sap.com › t5 › enterprise-resource-planning-q-a › xml-json-payload-slash-character-escaped › qaq-p › 12535109
XML - JSON Payload - slash character escaped - SAP Community
November 12, 2021 - #COE #BA01 Escape Character substitution for Special Characters in XML Payment Files in Enterprise Resource Planning Q&A 2022 Aug 04
Top answer
1 of 10
1711

If you use an appropriate class or library, they will do the escaping for you. Many XML issues are caused by string concatenation.

XML escape characters

There are only five:

"   &quot;
'   &apos;
<   &lt;
>   &gt;
&   &amp;

Escaping characters depends on where the special character is used.

The examples can be validated at the W3C Markup Validation Service.

Text

The safe way is to escape all five characters in text. However, the three characters ", ' and > needn't be escaped in text:

<?xml version="1.0"?>
<valid>"'></valid>

Attributes

The safe way is to escape all five characters in attributes. However, the > character needn't be escaped in attributes:

<?xml version="1.0"?>
<valid attribute=">"/>

The ' character needn't be escaped in attributes if the quotes are ":

<?xml version="1.0"?>
<valid attribute="'"/>

Likewise, the " needn't be escaped in attributes if the quotes are ':

<?xml version="1.0"?>
<valid attribute='"'/>

Comments

All five special characters must not be escaped in comments:

<?xml version="1.0"?>
<valid>
<!-- "'<>& -->
</valid>

CDATA

All five special characters must not be escaped in CDATA sections:

<?xml version="1.0"?>
<valid>
<![CDATA["'<>&]]>
</valid>

Processing instructions

All five special characters must not be escaped in XML processing instructions:

<?xml version="1.0"?>
<?process <"'&> ?>
<valid/>

XML vs. HTML

HTML has its own set of escape codes which cover a lot more characters.

2 of 10
118

New, simplified answer to an old, commonly asked question...

Simplified XML Escaping (prioritized, 100% complete)

  1. Always (90% important to remember)

    • Escape < as &lt; unless < is starting a <tag/> or other markup.
    • Escape & as &amp; unless & is starting an &entity;.
  2. Attribute Values (9% important to remember)

    • attr=" 'Single quotes' are ok within double quotes."
    • attr=' "Double quotes" are ok within single quotes.'
    • Escape " as &quot; and ' as &apos; otherwise.
  3. Comments, CDATA, and Processing Instructions (0.9% important to remember)

    • <!-- Within comments --> nothing has to be escaped but no -- strings are allowed.
    • <![CDATA[ Within CDATA ]]> nothing has to be escaped, but no ]]> strings are allowed.
    • <?PITarget Within PIs ?> nothing has to be escaped, but no ?> strings are allowed.
  4. Esoterica (0.1% important to remember)

    • Escape control codes in XML 1.1 via Base64 or Numeric Character References.
    • Escape ]]> as ]]&gt; unless ]]> is ending a CDATA section.
      (This rule applies to character data in general – even outside a CDATA section.)
Find elsewhere
🌐
Neowin
neowin.net › technical help & support › programming (c#, c++, java, vb, .net etc.)
How do I output a backslash \ character in XML? - Programming (C#, C++, JAVA, VB, .NET etc.) - Neowin
January 31, 2006 - How do I output a backslash \ character in XML? Ive found a couple of articles saying use: \ but that still errors.
🌐
W3Schools
w3schools.io › xml-escape-characters
Learn Which characters to escape for XML components - w3schools
This tutorial covers the essentials of Why Escape is required for XML and examples for Escape characters for content text, attributes, CDATA, and comments
🌐
Liquid Technologies
liquid-technologies.com › Reference › Glossary › XML_EscapingData.html
Escaping XML Data
Escaping XML Data Adding control characters ('<', '>', ''', '"', '&') into xml data can cause the parser to miss understand the resulting data. The solution is to escape the control characters so that the parser can interpret them correc
🌐
Advanced Installer
advancedinstaller.com › user-guide › xml-escaped-chars.html
XML escaped characters
For example, if you add an existing XML file or create a new one in your project and insert a special XML character in one of its elements, let's say < character, when you will build the project, Advanced Installer will automatically escape this character, replacing it with &lt;. The result is that the XML document installed by the built package will contain the escaped character making possible the correct interpretation of the XML code.
🌐
Experts Exchange
experts-exchange.com › questions › 21972190 › Encode-forward-slash-in-XML.html
Solved: Encode forward slash in XML | Experts Exchange
August 30, 2006 - Hi, I wonder how I encode a forward slash in xml. <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <Colors> <Color>black/white</Color> </Colors> Thanks in advance! Zero AI Policy · We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads. Gertone (Geert Bormans)🇧🇪 · Hi risj, no need to escape "/" in character content the XML snippet you posted is wellformed Cheers!
🌐
LabKey
labkey.org › home › Support › Developer Forum › announcements-thread.view
Escape forward slash in xml: /home/Support/LabKey Support Forum
August 22, 2012 - LabKey Support · Sign In · JavaScript is disabled. For the full experience enable JavaScript in your browser · Messages · Escape forward slash in xml · LabKey Support Forum (Inactive) · View Message · view list print · Powered by LabKey | Privacy Policy
🌐
Wrox
p2p.wrox.com › xslt › 37030-how-escape-forward-slash-xpath-xslt.html
How to Escape Forward Slash in XPath/ XSLT?
January 10, 2006 - I have an XML document that describes the structure of a web site. To determine selected state, I need to do something like this: /site/level1::descend
🌐
GitHub
github.com › rack › rack › issues › 27
HTML escape of slash is recommended by OWASP · Issue #27 · rack/rack
June 13, 2010 - They recommend escaping apostrophes ... to the 5 characters significant in XML (&, <, >, ", '), the forward slash is included as it helps to end an HTML entity....
Author   thinkerbot