468,257 Members | 1,414 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,257 developers. It's quick & easy.

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.
Nov 18 '06 #1
3 1863
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" <St******@discussions.microsoft.comwrote in message
news:DE**********************************@microsof t.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.

Nov 18 '06 #2
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" <St******@discussions.microsoft.comwrote in message
news:DE**********************************@microsof t.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
Nov 19 '06 #3
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/
Nov 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Christian Schmidbauer | last post: by
2 posts views Thread by bissatch | last post: by
23 posts views Thread by Stanimir Stamenkov | last post: by
36 posts views Thread by Roedy Green | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.