By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,933 Members | 1,563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,933 IT Pros & Developers. It's quick & easy.

Xml Serialization - Defaulting to XmlIgnore?

P: n/a
I have a pretty complex data structure which I want to serialize to
and from XML, I have tried the .net 2.0 serialization engine and
proved that it will work for my structure.

However by default the serialization engine outputs every property it
comes across and I was wondering if it would be possible to get it to
behave as if everything had the XmlIgnore attribute attached unless
another xml serialization attribute with specified? I.E. output
nothing unless an XmlElement or XmlArray etc attribute was attached.



Mar 5 '07 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Not without doing it yourself via IXmlSerializable. However, a viable
alternative may be to use the .Net 3.0 "WCF" serialization
[DataContract] and DataContractSerializer; this is "opt in" rather
than "opt out", plus can work on fields or properties equally. The
main difference is replacing [Serializable] with [DataContract], and
adding [DataMember] (with optional name) to the things you want. Oh,
and everything is "element" (i.e. there is no XmlAttribute equivalent
AFAIK); I guess this keeps things simple with nullables etc.


Mar 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.