.NET Xml question

G

Guest

I have an xml file with the data types for elements and attributes defined in
xsd. If I load the xml in XmlDocument, How do I get the element and attribute
values in its >NET types. For example, I have an Age (could be element or
attribute) which is defined as 2 byte interger in xsd. After I load the xml
in XmlDocument, how do I get the value as Int16 .NET data type when going
through the XmlNode?
 
D

Dave Sexton

Hi Roy,

Try using the XmlReader.Create() method to obtain an XmlReader. The XmlReader class provides a method named ReadContentAs that
accepts a Type and returns an object. To identify the data type of the current node as defined in the schema try using the
following code:

reader.SchemaInfo.SchemaType.TypeCode

where reader is an XmlReader instance that is validating your XmlSchema. You can assign your schema to the reader in the Create
method using an XmlReaderSettings object.

XmlReader.Create on MSDN:
http://msdn2.microsoft.com/en-US/library/system.xml.xmlreader.create.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top