<?xml version="1.0" encoding="utf-8" ?> <Table> <ID >1</ID> <Name >Joe</Name> <Street1 >123 Main Street</Street1> <Street2 >Apt #1</Street2> <City >City</City> <County >County</County> <State >State</State> <Zipcode >Zip</Zipcode> <Province >Province</Province> <Country >Country</Country> <Phone >1234567890</Phone> <Fax >1234567890</Fax> </Table>I have the following xsd file:
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Table"> <xs:complexType> <xs:sequence> <xs:element name="ID" type="xs:int" /> <xs:element name="Name" type="xs:string" /> <xs:element name="Street1" type="xs:string" /> <xs:element name="Street2" type="xs:string" /> <xs:element name="City" type="xs:string" /> <xs:element name="County" type="xs:string" /> <xs:element name="State" type="xs:string" /> <xs:element name="Zipcode" type="xs:string" /> <xs:element name="Province" type="xs:string" /> <xs:element name="Country" type="xs:string" /> <xs:element name="Phone" type="xs:unsignedInt" /> <xs:element name="Fax" type="xs:unsignedInt" /> </xs:sequence> </xs:complexType> </xs:element></xs:schema>
(You can assume the xml, and xsd files are correct, hopefuly I didn't typo when I c/p).I've written the following C# code to read in the xml into a SQLDataReader. I'd like the column names to corrospond to the name of the nodes(for example "ID", "Name", "Street1" etc...).
Code Sample #1
DataTable table = new DataTable("Table");SqlDataAdapter adaptor = new SqlDataAdapter();SqlDataReader reader = null;string schema = "RelativePath/to/Schema.xsd";string xml = "RelativePath/to/File.xml";table.ReadXmlSchema(schema);table.ReadXml(xml);