what can i do if i want to include "<" or ">" in xml document.

hi everybody,
i am useing some classes which in System.Xml to deal with xml document. what 
can i do if the document include "<" or ">"?

Thanks.
0
StevenXu (4)
11/18/2006 10:20:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
536 Views

Similar Articles

[PageSpeed] 15

Escape them to "&lt;" and "&gt;" (excluding the surrounding quotes.

">" is ususally safe even unescaped in most contexts.

Sometimes it becomes necessary to escape the quotes and the apostrophe 
characters -- accordingly -- with "&quot;" and "&apos;"

Another character to escape almost always is the ampersand character 
itself -- this is escaped as "&amp;"


Cheers,
Dimitre Novatchev


"Steven.Xu" <StevenXu@discussions.microsoft.com> wrote in message 
news:DED43E7B-486A-45C9-A566-F1DACEC8C429@microsoft.com...
> hi everybody,
> i am useing some classes which in System.Xml to deal with xml document. 
> what
> can i do if the document include "<" or ">"?
>
> Thanks. 


0
11/18/2006 11:36:45 PM
On Sat, 18 Nov 2006 15:36:45 -0800, Dimitre Novatchev wrote:

> Escape them to "&lt;" and "&gt;" (excluding the surrounding quotes.
> 
> ">" is ususally safe even unescaped in most contexts.
> 
> Sometimes it becomes necessary to escape the quotes and the apostrophe 
> characters -- accordingly -- with "&quot;" and "&apos;"
> 
> Another character to escape almost always is the ampersand character 
> itself -- this is escaped as "&amp;"
> 
> 
> Cheers,
> Dimitre Novatchev
> 
> 
> "Steven.Xu" <StevenXu@discussions.microsoft.com> wrote in message 
> news:DED43E7B-486A-45C9-A566-F1DACEC8C429@microsoft.com...
>> hi everybody,
>> i am useing some classes which in System.Xml to deal with xml document. 
>> what
>> can i do if the document include "<" or ">"?
>>
>> Thanks.

Also, this is a .NET XML newsgroup, so presumably you're using .NET to
read/write these strings?
If so, XmlTextReader/Writer and XmlDocument both escape the contents
automatically, so you generally don't have to worry about it.

Cheers,
 Gadget
0
gadget1 (19)
11/19/2006 3:09:45 AM
Steven.Xu wrote:

> i am useing some classes which in System.Xml to deal with xml document. what 
> can i do if the document include "<" or ">"?

Do you want to create an XML document that contains those characters? As 
already pointed out if you use Xml(Text)Writer then escaping is done 
automatically if you use the proper API calls (e.g. WriteElementString).

It is not clear whether you want to create such a document or whether 
you want to parse an existing document. Parsing markup with unescaped 
'<' or '&' content with an XML parser will give you a parse error as the 
markup is not well-formed XML.

-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
11/19/2006 1:02:17 PM
Reply:

Similar Artilces: