Reputation: 450
I have a question for XML document special chars, I'm using & in on of the value of the item in XML and TXMLDoc Delphi parser is complaining about it.
I search for some XML parsing options but none of them concerning special chars,
any ideas?
Example:
<Configuration>
<Configuration_item>
<view_name value="some view & name"/>
....
Regards, Mika
Upvotes: 2
Views: 3478
Reputation: 24319
&
, <
and >
are the special characters you'll want to watch out for, and within an attribute also "
. &
is kind of like the XML escape character.
They can be escaped thus:
&
=> &
<
=> <
>
=> >
"
=> "
(Actually, and oddly, you don't really need to escape >
within an attribute, only <
. Also, if you use '
instead of "
for your attribute delimiters, instead of having to escape "
as "
you need to escape '
as '
. See the AttValue reference in the XML specification for details.)
Upvotes: 4
Reputation: 150198
Dav and lavinio are right.
If you have a block of text with lots of special characters you might want to enclose it in CDATA instead.
Upvotes: 2
Reputation: 527328
Use &
to represent an ampersand. The reason you need to do this is because & is a special character in XML - specifically, the character used to indicate the start of an XML entity, which is used to specify characters in the content that would (ironically) otherwise be special/complex characters.
<view_name value="some view & name"/>
Other common XML entities:
"
<
(short for less-than)is
>
(short for greater-than)
For more info:
http://www.xml.com/pub/a/2001/01/31/qanda.html
Upvotes: 8