Re: XML Serializer



On Mar 10, 1:58 am, FR <nos...@xxxxxxxxxx> wrote:
I want use annotation for format XML like this with xml serializer:
<myclass>
        <text><![CDATA[
                SOME <XML> TEXT
                ]]></text>
</myclass>

The question is - why? It shouldn't matter whether the output uses
CDATA to escape special characters, or character entities -
semantically, the meaning of XML remains exactly the same, and, unless
you have text data that consists entirely of reserved chars, the size
difference will be negligible.

How format Annotation in C#?? it's possible?
public class MyClass
{
     string _data;

     [XmlElement]--> annotation
     public string text{ get; set; }

}

The second Chance for me it's use IXmlSerializable Interface...
i must use this o there's other method?

I'm not aware of any other than implementing IXmlSerializable and
generating XmlCDataSection nodes manually.

Note that sometimes you can get away with doing it only for a specific
subelement rather than the entire class. E.g.

public class MyClass
{
public class TextElement : IXmlSerializable { string
_data; ... } // do custom CDATA serialization here

     [XmlElement]
     public TextElement text{ get; set; }

// other stuff that works fine with default serialization
...
}

Of course, this means tweaking your classes to look the way
XmlSerializer expects them too, but then you normally end up doing
that anyway (which is why it's a good idea not to do it with your
domain model directly).
.



Relevant Pages