Link to home
Start Free TrialLog in
Avatar of aphillips
aphillipsFlag for Australia

asked on

Special characters in attributes


I am reading/writing XML using DOM from C++.  Some attributes are a C-like expression that can include &, <, > as well as single- and/or double-quotes.

I have found lots of info on XML attributes that basically says if you want to use a double-quote enclose the attribute in single-quotes and vice-versa.  None address the issue of including both double- and single-quotes in the same attribute text.

Also, I assume that I have to converts and ampersand (&) to &amp; when writing the XML, and convert back when reading.  Putting an & in the attribute text does not work, although I have never read that it should be a problem.
ASKER CERTIFIED SOLUTION
Avatar of Wayne Bradney
Wayne Bradney
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aphillips

ASKER

wbradney said:
> & becomes &amp;
> ' becomes &apos;
> " becomes &quot;
Thanks, I have never seen &apos; or &quot; before.  I also didn't know you could use &amp; in an attribute string.

> If you're using the DOM, the conversions should be transparent ...

You are right.  I was creating the XML by hand for testing.  The & was giving errors when reading the attributes but using DOM to create the XML this all becomes transparent.