views:

1699

answers:

4

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...

+7  A: 

Hi Alpants.

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

Ray Booysen
‘%’ does not need encoding in XML. ‘>’ can need encoding in one particular niche situation. ‘"’ or ‘'’ will need encoding inside attribute values (whichever was used as the delimiter for that attribute).
bobince
+1  A: 

You probably have a constrained attribute, as defined in the XML Schema.

I do not know what you mean by XML formatting.

leppie
+1  A: 

I can't see why a value of "Jim/Bob" would need escaping or cause XML any problems at all.

AnthonyWJones
+1  A: 

There's no predefined entity reference for it, but you can use a character reference: “&#47;”.

However, you don't need to escape / for inclusion in XML. You might have to include it for inclusion in something else, for example a URI path part. But then you'd have to escape it for that format first; the application that picks up the URI wouldn't have any way to know if you'd encoded it in the XML or not.

bobince