tags:

views:

243

answers:

2

I'm having some trouble with the ReadXmlSchema and ReadXml methods for a DataTable. I'm getting the error "DataTable does not support schema inference from Xml".

Code Snippet: I've tried

Table.ReadXmlSchema(new StringReader(File.ReadAllText(XsdFilePath)));
Table.ReadXml(new StringReader(File.ReadAllText(XmlFilePath)));

And

Table.ReadXmlSchema(XsdFilePath);
Table.ReadXml(XmlFilePath);

Xml Snippet:

<ScreenSets>
  <ScreenSet id="Credit 1">
    <Screen xmlFile="sb-credit1.en.xml" tabText="Recommendation" isCached="false">
      <Buttons>
        <Button id="btnClosePresentation"/>
      </Buttons>
    </Screen>
  </ScreenSet>
  <ScreenSet id="Credit 2">
    <Screen xmlFile="sb-credit2.en.xml" tabText="Recommendation" isCached="false">
      <Buttons>
        <Button id="btnClosePresentation"/>
      </Buttons>
    </Screen>
  </ScreenSet>
  <ScreenSet id="Credit 3">
    <Screen xmlFile="sb-credit3.en.xml" tabText="Recommendation" isCached="false">
      <Buttons>
        <Button id="btnClosePresentation"/>
      </Buttons>
    </Screen>
  </ScreenSet>
</ScreenSets>

Xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="ScreenSets">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="ScreenSet">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Screen">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="Buttons">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element maxOccurs="unbounded" name="Button">
                            <xs:complexType>
                              <xs:attribute name="id" type="xs:string" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                  <xs:attribute name="xmlFile" type="xs:string" use="required" />
                  <xs:attribute name="tabText" type="xs:string" use="required" />
                  <xs:attribute name="isCached" type="xs:boolean" use="required" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
+1  A: 

Your schema and data do not represent a single table and are not in a format that is recognized by .net Data objects such as DataSet and DataTable.

Your best bet is to design a dataset in the designer and then call dataset.WriteXmlSchema/Data to get your exemplar .xsd.

Sky Sanders
so does the datatable not support nested elements? and would this make more sense to load into a dataset instead?
MasterMax1313
Looks like you / I was correct, DataSet is the way to go. You'd just have to find a way to represent the various parts graphically. Oh well, thanks for the help.
MasterMax1313
@MasterMax1313 - no, table is a flat record of simple types. A dataset will let you compose your tables into the shape you want. And, as you found out, pushing arbitrary xsd into a datatable/set is not the best plan. ;-) glad you got it figured out.
Sky Sanders
A: 

If u want the xml file from database u can use,dataset.WriteXml("filepath", XmlWriteMode.WriteSchema)

Then,to read the file into the table, dataset.ReadXml("filepath", XmlReadMode.ReadSchema) table=dataset.tables(0)

Provided u have filled the schema of the table to that of the xmlfileschema.

ManojAnavatti