all groups > dotnet xml > july 2003 >
You're in the

dotnet xml

group:

XmlNode -> Schema -> Object


XmlNode -> Schema -> Object Brad Quinn
7/29/2003 4:16:46 PM
dotnet xml:
Lets say I have an XmlNode that validates against some schema. I also have
a class that was generated by the xsd tool using said schema.

What is the best way to get from an XmlNode to an instance of the class?

Re: XmlNode -> Schema -> Object Dino Chiesa [MSFT]
7/29/2003 5:38:48 PM
System.Xml.Serialization.XmlSerializer.Deserialize()
accepts an XmlReader.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassDeserializeTopic3.asp

and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlNodeReaderClassctorTopic.asp


[quoted text, click to view]

Re: XmlNode -> Schema -> Object Brad Quinn
7/30/2003 10:24:47 AM
Thanks Dino,

Going the other way (I know I didn't mention this) doesn't seem as elegant.

Is there a better way than this?

// slightly paraphrased
Stream stream = new MemoryStream();
new XmlSerializer( typeof(MyObject) ).Serialize( stream, myObject );
stream.Seek( 0, SeekOrigin.Begin );
XmlDocument doc = new XmlDocument();
doc.Load( stream );
return doc.DocumentElement;

Thanks again,
Brad

[quoted text, click to view]

AddThis Social Bookmark Button