I have spent about half a day searching for an answer to this question and am slowly becoming frustrated. I am working with a Web service that returns an XmlNode as its response. I would like to be able to take the XML data reference by the node and view it with a data grid view. Does any one know if this is possible?
I am using the following code:
// submit command to webserver
XmlNode response = SubmitToWebserv((XmlElement)IssueNode, state.Get);
// create XML reader to read response
XmlReader reader = new XmlNodeReader(response);
// create a data table to hold response
DataTable dt = new DataTable();
dt.ReadXmlSchema(reader);
// read data into data table
dt.ReadXml(reader);
It throws exception: DataTable does not support schema inference from Xml. The thing is, the schema is included in the XML referenced by response… So I am at a loss.
I suggest you try that using DataSet instead of DataTable. I don’t know that it will work, but it makes sense that it would. The schema might have included more than one table.
OTOH, did the XmlNode include a schema at all?
I recommend you look at this in the debugger. In particular, watch to see which node the XmlReader is positioned on. I’m not 100% convinced it will advance as you want, from the wrapping element, to the schema, then to the data.
Also, is there an element wrapping the schema and data:
Or are the schema and data elements top-level nodes. This would be a fragment.