_Raeldor_

Hi,

I have text values with angled brackets and it's throwing my xml out. Even as attributes, I get the error

The character '<' cannot be used in an attribute value.

These characters are valid data values... is there a workaround for this

Thanks
Rael



Re: XML and the .NET Framework How to handle Angled Brackets in Text

Vinod.S.Nair

Hi,

You can very well use &lt; and &gt; replacing '<' and '>'. But my preference will be to use CDATA section. Please have a look at below mentioned link. May be usefull.

http://msdn2.microsoft.com/en-us/library/ms256076.aspx

Regards,

Vinod S Nair





Re: XML and the .NET Framework How to handle Angled Brackets in Text

Robert Rossney

The only time you'll have trouble with markup characters in text is if you're formulating XML through string manipulation. There are very few circumstances in which this is not a terrible idea.

I can't emphasize that enough. I've seen a lot of code that does this over the last eight or nine years. Nearly all of it has been flawed in some way. (My favorite was in an actual production application in the banking industry that prevented markup characters from showing up in XML messages by applying a regular expression to every form field that transformed them to asterisks!)

You should always form XML documents by using framework classes. Always. If you do this, everything will just work.

There are very few jobs that CDATA is the right tool for. Base64-encoded objects, script code, and embedded XML samples are about the only ones. If you're creating CDATA sections because you want to avoid the work of escaping markup characters, you have taken a very wrong turn.