DataTable does not support schema inference from Xml.?

monkey_boys picture monkey_boys · Dec 20, 2009 · Viewed 43.6k times · Source
<?xml version="1.0" encoding="utf-8"?>
<PHP_Adapter>
  <Adapter>
    <ID>11</ID>
    <Provider>22</Provider>
    <Connectstring>33</Connectstring>
  </Adapter>
</PHP_Adapter>

This my Xml file what wrong?

    bool CheckAdapterExist(string aid)
    {
        DataTable dt = new DataTable();
        dt.ReadXml(axml);
        MessageBox.Show(dt.Rows[0]["ID"].ToString());

        return true;
    }

Answer

Adriaan Stander picture Adriaan Stander · Dec 20, 2009

Try using a Dataset rather

DataSet ds = new DataSet();
ds.ReadXml(@"d:\test.xml");
MessageBox.Show(ds.Tables[0].Rows[0]["ID"].ToString());

Found at

DataTable.ReadXml(filename) throws an error. Why?