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...
-
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
bobince : ‘%’ 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). -
You probably have a constrained attribute, as defined in the XML Schema.
I do not know what you mean by XML formatting.
-
I can't see why a value of "Jim/Bob" would need escaping or cause XML any problems at all.
-
There's no predefined entity reference for it, but you can use a character reference: “/”.
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.
0 comments:
Post a Comment