Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2003

Tip: Looking for answers? Try searching our database.

XmlNode -> Schema -> Object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brad Quinn - 29 Jul 2003 22:16 GMT
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?
Dino Chiesa [MSFT] - 29 Jul 2003 22:38 GMT
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?
Brad Quinn - 30 Jul 2003 16:24 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.