Can't load Dataset with XML and Schema from another Dataset
I'm trying to pass a dataset as xml from my web service to my web page. My example code is below and gives me a "Root element is missing" error.
Here's my code behind:
' This is actually a web service methodPublic Function GetDatasetXml(ByRef sXmlSchema As String) As String Dim sSQL As String = "SELECT ProductId, Name, Color FROM Product WHERE Color IS NULL" Dim ds As New Dataset = DbHelper.OpenDataset(sSQL) sXmlSchema = ds.GetXmlSchema() return ds.GetXml()End FunctionPublic Sub BindMarkup Dim sXMLSchema As String = String.Empty Dim sXML As String = GetDatasetXml(sXMLSchema) Dim readerXMLSchema As XmlReader = XmlReader.Create(New StringReader(sXMLSchema)) Dim readerXML As New System.IO.StringReader(sXML) Dim ds As New DataSet ds.ReadXmlSchema(readerXML) ds.ReadXml(readerXML, XmlReadMode.ReadSchema) Me.rptList.DataSource = ds Me.rptList.DataBind()End Sub
I tried this originally without using the XML Schema but that failed because the Color field is null and caused the repeater to complain the Color field wasn't found. So I know I need the schema but I can't figure out how to get this to work.