Re: [xml] Special chars in XML



On Wed, 2010-12-29 at 17:35 -0500, samaram s wrote:

I am working with libxml2 library for one of my application.
But in my data there are few strings which has some special characters  like
('&' , < , >) etc

You need to escape some of these characters in your data.

For & use &amp; instead.

For < and > use &lt; and &gt;

Inside attribute values, for " and ' use &quot; and &apos;
(you can quote them in other places too but it is not necessary)

For example,
    <activity whose="Susan's">R & D budget < 30000</activity>
might be quoted as
    <activity whose="Susan's">R &amp; D budget ^lt; 30000</activity>

You only need to quote " in attribute values if " was used for the
quotes and the same with ', like this
    <activity whose='Susan&apos;s'>....


You do not need to use a DTD for any of this.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]