Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inheritance vs xml

1 view
Skip to first unread message

csharpula csharp

unread,
May 12, 2008, 9:54:35 AM5/12/08
to
Hello!

I have inheritance between classes which are the result of xml
serialization.
My question is how can I insure in serializaion stage that the hierarchy
in xml is according to inheritance hierarchy in classes?

Thank you very much!

*** Sent via Developersdex http://www.developersdex.com ***

Ignacio Machin ( .NET/ C# MVP )

unread,
May 12, 2008, 11:44:18 AM5/12/08
to

Hi,

Can you give more details? it;s not very clear where is your problem.

Alex Meleta

unread,
May 12, 2008, 5:12:28 PM5/12/08
to
Hi,

E.g. try to deserialize the class tree, then validate the result.

Regards, Alex
[TechBlog] http://devkids.blogspot.com

cc> Hello!
cc>
cc> I have inheritance between classes which are the result of xml
cc> serialization.
cc> My question is how can I insure in serializaion stage that the
cc> hierarchy
cc> in xml is according to inheritance hierarchy in classes?
cc> Thank you very much!
cc>
cc> *** Sent via Developersdex http://www.developersdex.com ***
cc>


csharpula csharp

unread,
May 13, 2008, 4:08:31 AM5/13/08
to

My question is : if I have ClassA:ClassB and in xml Class B element has
a memeber which is not of type A or B - is there an error in loading
this xml?

Marc Gravell

unread,
May 13, 2008, 4:29:13 AM5/13/08
to
> My question is : if I have ClassA:ClassB and in xml Class B element has
> a memeber which is not of type A or B - is there an error in loading
> this xml?

See XmlAnyAttributeAttribute / XmlAnyElementAttribute:

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlanyattributeattribute.aspx
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlanyelementattribute.aspx

Marc

Marc Gravell

unread,
May 13, 2008, 4:32:10 AM5/13/08
to
Also - it suggests no error is raised by default, but you can detect
unknown nodes and do what you want:

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.unknownnode.aspx

"By default, after calling the Deserialize method, the XmlSerializer
ignores XML nodes of unknown types. However, you can use this event to
handle such node types."

http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.unknownattribute.aspx

"By default, after calling the Deserialize method, the XmlSerializer
ignores XML attributes of unknown types. However, you can use this event
to handle such node types."

Marc

0 new messages