Reputation: 7718
As part of an XML node attribute, I need to pass up HTML characters as part of an attribute value, such as hello" />. I can't use CDATA as part of the value of the node, as lots of other systems use this method and I cannot afford to break or rewrite that process, so I'm stuck with this.
I can't HTML encode the values, as they're used inside of an email and are subsequently outputted literally as HTML encoded values (<br >hello, for example).
Is there a way to escape HTML (specifically, the < character) and allow me to keep un-encoded HTML inline as an attribute? Thanks.
Upvotes: 2
Views: 5142
Reputation: 109613
The XML characters <>&"
must be escaped identical to the HTML entities <
and so on. Using XML APIS will receive/store the original character. Other character entities in HTML should be converted to UTF-8. Numeric entities, hex (ü
) and decimal (࣭
) are simple, but for named entities (•
) one needs a Library. (If one wants to achieve completeness.)
Upvotes: 3