XmlDataSource vs DataSource
-
I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a
StringReader
and useReadXml
. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into anXMLDataSource
. The second one doesn't - loading the XML file into aDataSource
, viaReadXML
. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a fileXmlDataSource xds = new XmlDataSource(); xds.DataFile = ("d:/test.xml"); GridView1.DataSource = xds; GridView1.DataBind();
doesn't work as it only seems to look at root node.
DataSet ds = new DataSet(); System.IO.StreamReader str = new StreamReader("d:/test.xml") ; StringReader rdr = new StringReader(str.ReadToEnd()); ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string** GridView1.DataSource = ds; GridView1.DataBind();
Any ideas?
Regards Malc *********************************************
-
I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a
StringReader
and useReadXml
. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into anXMLDataSource
. The second one doesn't - loading the XML file into aDataSource
, viaReadXML
. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a fileXmlDataSource xds = new XmlDataSource(); xds.DataFile = ("d:/test.xml"); GridView1.DataSource = xds; GridView1.DataBind();
doesn't work as it only seems to look at root node.
DataSet ds = new DataSet(); System.IO.StreamReader str = new StreamReader("d:/test.xml") ; StringReader rdr = new StringReader(str.ReadToEnd()); ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string** GridView1.DataSource = ds; GridView1.DataBind();
Any ideas?
Regards Malc *********************************************
err maybe you should use ReadXmlSchema().
-
I have unmanged DLL (legacy - can't touch it!) which returns an XML string. I want to bind this string to a datagrid....easy...or it should be. But I can't. I've isolated the problem below. To get the xml string into a dataset, I use a
StringReader
and useReadXml
. But when binding to Datagrid, it only shows the root node if I haven't pre bound the columns, or if I have, it complains the field isn't there (as it only exists in teh child nodes). I have saved the output from the Unmanaged DLL to an XML file which can be parsed, so the format is correct. To test, I use two methods of populating the grid. The first one works fine, loading the XML file into anXMLDataSource
. The second one doesn't - loading the XML file into aDataSource
, viaReadXML
. It is this second optoin I need to work, or some method of doing this where i can pass an XML string in. works a treat, but I can't use as I have to receive from a string, not a fileXmlDataSource xds = new XmlDataSource(); xds.DataFile = ("d:/test.xml"); GridView1.DataSource = xds; GridView1.DataBind();
doesn't work as it only seems to look at root node.
DataSet ds = new DataSet(); System.IO.StreamReader str = new StreamReader("d:/test.xml") ; StringReader rdr = new StringReader(str.ReadToEnd()); ds.ReadXml(rdr);//**<-- this is the KEY bit as I need to load from a string** GridView1.DataSource = ds; GridView1.DataBind();
Any ideas?
Regards Malc *********************************************
The Dataset, read from an XML string contains multiple tables. The first table (the default) is the root node, the second table, contains the child nodes...so...changing the following line works a treat..
//GridView1.DataSource = ds; //defaults to Tables[0] which root node
GridView1.DataSource = ds.Tables[1];//child nodes - marvellous.Regards Malc *********************************************