Click here to Skip to main content
15,936,337 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
hello,
ive got an xml schema wich is placed inside of an xml file
it is placed as one of the descendants of the first Node , this xml file represnt a table
<newdataset>
   <xs:schema .....="" xmlns:xs="#unknown">
         .
          <xs:element name="Table">
          <xs:complextype>
              <xs:sequence>
                <xs:element name="OrderID" type="xs:int" minoccurs="0" />
                <xs:element name="ProductID" type="xs:int" minoccurs="0" />
                <xs:element name="UnitPrice" type="xs:decimal" minoccurs="0" />
                <xs:element name="Quantity" type="xs:short" minoccurs="0" />
                <xs:element name="Discount" type="xs:float" minoccurs="0" />
              </xs:sequence>
            </xs:complextype>
          </xs:element>
          .
          .
   </xs:schema>
   <record>
        // FIELD NODES
   </record>
   <record>
       // FIELD NODES
   </record>
   .
   .
       // MORE RECORDS 
<newdataset>
</newdataset></newdataset>

i need to retrive the the name and the type of the fields in order to create an Entity that would represent a record , i cannot use built in ADO.NET function to create a dataset from this file.
i could use xmlDocument and traverse threw the schema untill finding the node with the name="table" , attribute .
im looking for a simple better looking way to do the above .
Linq to xml would of been the most appropriate way but it seems to have a problem with
Descendants("xs:element") with the ":" to be more specific .
thanks in advance .
Posted

1 solution

Hello Dear
if file which you want load schema from it, is completely true , you can do this to load schema from a file to DataSet :
DataSet Dset = new DataSet();
Dset.ReadXml("FilePath");

or
DataSet Dset = new DataSet();
Dset.ReadXmlSchema("FilePath");

ReadXml("FileName") method of DataSet loads Schema and Data from XML file
ReadXmlSchema("FileName") method of DataSet loads just Schema from XML file

if you want to write schema and data to a XML file you can do these :
MIDL
Dset.WriteXml("FilePath");
Dset.WriteXmlSchema("FilePath");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900