473,513 Members | 2,339 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlNode -> Schema -> Object

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?
Nov 11 '05 #1
2 2199
System.Xml.Serialization.XmlSerializer.Deserialize ()
accepts an XmlReader.
http://msdn.microsoft.com/library/en...lizeTopic3.asp

and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode
http://msdn.microsoft.com/library/en...sctorTopic.asp
"Brad Quinn" <br********@yahoo.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl...
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?

Nov 11 '05 #2
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

"Dino Chiesa [MSFT]" <di****@microsoft.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
System.Xml.Serialization.XmlSerializer.Deserialize ()
accepts an XmlReader.
http://msdn.microsoft.com/library/en...lizeTopic3.asp
and you can create a System.Xml.XmlNodeReader from a System.Xml.XmlNode
http://msdn.microsoft.com/library/en...sctorTopic.asp

"Brad Quinn" <br********@yahoo.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl...
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?


Nov 11 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1228
by: Dan Bolser | last post by:
I would like to make an RDB from XML, how can I automatically create an RDB schema from an XML schema? Am I asking the wrong question? Ta, Dan.
0
1126
by: Andrea N. | last post by:
I'm new to .NET XML classes, so here my dilemma I really like the XMLDataDocument concept of synchronizing automatically XMLDocument and DataSet with a common schema. Can I automatically...
1
1711
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net...
0
945
by: Michael.McD | last post by:
I would like to store an object graph in a SQL tables (that map via a schema generated using xsd.exe to my objects properties - generated using xsd.exe) and then restore these objects from said...
4
1869
by: Sindarian | last post by:
This just seems like the most basic thing, but I can't find a simple description of this process anywhere and in here, everone is talking about going the other way :( I had .NET create an XML...
5
5376
by: Jeff | last post by:
We are using .Net and the wsdl Utility to generate proxies to consume web services built using the BEA toolset. The data architects on the BEA side create XML schemas with various entities in...
1
1634
by: easy.lin | last post by:
.... <object id="10">door</object> .... I try to write this in clipse XSD editor <element name="object" type="string"> <attribute name="id" type="int"></attribute> </element> but get wrong...
5
3633
by: markus.meier | last post by:
Hi, I'm searching a tool to generate XML files based on an existing XML schema file. Does somebody know a free tool that supports this feature? Thanks Markus
1
10327
by: =?Utf-8?B?TWFuaXNoIEJhZm5h?= | last post by:
Hi, I am getting following error while validating xml file with schema using ReaderSettings in .NET 2.0 "Line: 0 - Position: 0 - The root element of a W3C XML Schema should be <schemaand its...
0
7175
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3235
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.