Home › Forums › XMetaL Tips and Tricks › Workaround: Automatic replacement of unescaped < > & characters in attributes › Reply To: Workaround: Automatic replacement of unescaped < > & characters in attributes
Reply to: Workaround: Automatic replacement of unescaped < > & characters in attributesJune 8, 2011 at 11:22 am
I took a detailed look at the XML Recommendation yesterday and remembered that having the character > inside an attribute value is actually not illegal (it does mention something fairly vague about “you may escape…” or similar). When it appears in an attribute value XMetaL with not complain either (which is correct).
There is no harm (from an XML Recommendation standpoint and from an “authoring in XMetaL” standpoint) in escaping this character. It seems to suit my emotional need to 'balance things' (so it mirrors < when they both happen to be present) so I will leave it in this demo. If you don't want this script to escape > it should be quite easy to remove those few lines that do that.
For the record, what the XML Recommendation says distills down to the following. It should sound simple when stated here in point form but it really is a lot of reading and not all information is located together nor is it a straightforward read (unless you are used to reading W3C specs and their interesting notations).
1. You must never have < in an attribute value and it must always be escaped as <
2. You may choose to escape > as > but you don't need to.
3. The & character must be escaped as &
4. You may escape ” or ' in an attribute value in order to use either ” or ' as the character that denotes the attribute boundary (the character surrounding the attribute value).
5. You may use ” inside an attribute as long as ' is used to denote the attribute boundary (the character surrounding the attribute value), or vice-versa.
6. If both ” and ' are present in an attribute value then at least one of them will need to be escaped.