Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Entity for "/"?

So I'm writing some XML generating code, and found that the following attribute value was screwing up the XML formatting:

"Jim/Bob"

So I looked into the XML Entities used as escape sequences and every list I saw did not include one for the forward slash. Am I missing something obvious here? Seems like the sort of thing you'd want to escape...

like image 940
Alpants Avatar asked Feb 11 '09 22:02

Alpants


People also ask

What is XML entity reference?

An entity reference is a group of characters used in text as a substitute for a single specific character that is also a markup delimiter in XML.

What are the two types of entity in XML?

In general, we have three types of entities: internal entities, external entities, and parameter entities.

What is character entity in XML?

In contrast, a character entity reference refers to a character by the name of an entity which has the desired character as its replacement text. The entity must either be predefined (built into the markup language) or explicitly declared in a Document Type Definition (DTD).

What is entity and element in XML?

As we said previously, an XML DTD is a collection of XML entity and element declarations and comments. Entities are name/value pairs that make the DTD easier to read and understand, while elements are the actual markup tags defined by the DTD, like HTML's <p> or <h1> tags.


4 Answers

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

like image 127
Ray Booysen Avatar answered Sep 29 '22 15:09

Ray Booysen


I know it turned out this wasn't the problem, but I thought it would be helpful to mention that, in addition to bobince's answer, the Fraction Slash HTML entity &frasl; looks just like a forward slash. Just in case anybody reaching this page actually does want an HTML entity for something representing a forward slash.

like image 45
sinisterstuf Avatar answered Sep 29 '22 16:09

sinisterstuf


I don't think the comments in this thread are entirely correct since if you use a schema (XSD) you could define elements with names Jim, Bob and Jim/Bob without any issues. But then when you want to define the element and entity:

<names>
  <Jim>Carrey</Jim>
  <Bob>Jones</Bob>
  <Jim/Bob>Six figured Hillbilly</Jim/Bob>
</names>

The problems are obvious.

like image 44
Eamonn Kenny Avatar answered Sep 29 '22 15:09

Eamonn Kenny


FYI although a slash is valid XML, watch out how it's being used downstream. We used it for connecting to an azure service bus queue. Azure itself generated keys with slashes in the connection strings, but then broke silently when we tried to use them. Escaping them with “&#47;” made it work

"Jim&#47;Bob"
like image 37
Adam Diament Avatar answered Sep 29 '22 16:09

Adam Diament