.NET Xml question

  • Thread starter Thread starter Guest
  • Start date Start date
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?
 
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
 
Back
Top