Re: XML Serializer
- From: Pavel Minaev <int19h@xxxxxxxxx>
- Date: Tue, 10 Mar 2009 10:30:36 -0700 (PDT)
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).
.
- References:
- XML Serializer
- From: FR
- XML Serializer
- Prev by Date: Re: Passing Parameters when initialising multiple threads
- Next by Date: Re: Can someone help me with this regular expression?
- Previous by thread: XML Serializer
- Next by thread: Re: XML Serializer
- Index(es):
Relevant Pages
|