> 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?
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
> System.Xml.Serialization.XmlSerializer.Deserialize()
> accepts an XmlReader.
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSerializationXm
lSerializerClassDeserializeTopic3.asp
> and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlXmlNodeReaderCl
assctorTopic.asp
> > 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?