How can I put an &
symbol in an attribute of an XML tag while keeping the XML valid?
<?xml version="1.0" ?> <a text="b&c"/>
When I use W3School's validator, I get the error:
EntityRef: expecting '
;
'
When several items are listed together, an ampersand may be used to tie together words or descriptions that would otherwise be less clear. For example, you might write: My favorite breakfasts are donuts, pancakes, biscuits & gravy, and bacon & eggs.
& is called an ampersand symbol (pronounced “AM- per-sand”). Essentially, it means “and”. It is used both (a) in the body of the paper as part of a citation and (b) at the end of the paper as part of a reference.
The ampersand should always be used when it's part of a company name, logo, proper noun, or title. This is one of the few cases where ampersand use isn't up for debate. For example, “M&M's” would never be written “M and M's.”
Use a character reference to represent it: &
See the specification:
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings "
&
" and "<
" respectively. The right angle bracket (>) may be represented using the string ">
", and MUST, for compatibility, be escaped using either ">
" or a character reference when it appears in the string "]]>
" in content, when that string is not marking the end of a CDATA section.
You can use these escape sequences :
< (less-than) - < or < > (greater-than) - > or > & (ampersand) - & ' (apostrophe or single quote) - ' " (double-quote) - "
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With