Solved

Can't load Dataset with XML and Schema from another Dataset

Posted on 2010-09-05
2
357 Views
Last Modified: 2013-11-07
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 method
Public 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 Function

Public 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

Open in new window

and my markup:
      <asp:Repeater ID="rptList" runat="server" >
        <ItemTemplate>
             <%# DataBinder.Eval(Container.DataItem, "ProductID")%><br>
             &nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Name")%><br>
             &nbsp;&nbsp;&nbsp;<%# DataBinder.Eval(Container.DataItem, "Color")%><br>
        </ItemTemplate>
      </asp:Repeater>

Open in new window


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.

Thanks in advance.
0
Comment
Question by:ZekeLA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 1

Author Comment

by:ZekeLA
ID: 33606812
A developer friend of mine gave me the solution. I'll post it if it's not proprietary.
0
 
LVL 1

Accepted Solution

by:
ZekeLA earned 0 total points
ID: 33799799
Here is the routine to create a dataset from the xml and xmlschema.
    Public Function XMLToDataSet( _
            ByVal sXml As String, _
            Optional ByVal sXmlSchema As String = "")

        ' Process XML
        Dim sr As StringReader = New StringReader(sXml)
        Dim xtr As XmlTextReader = New XmlTextReader(sr)

        ' Process Schema
        Dim srSchema As StringReader = Nothing
        Dim xtrSchema As XmlTextReader = Nothing
        If sXmlSchema.Length > 0 Then
            srSchema = New StringReader(sXmlSchema)
            xtrSchema = New XmlTextReader(srSchema)
        End If

        Dim ds As New DataSet
        If sXmlSchema.Length > 0 Then
            ds.ReadXmlSchema(xtrSchema)
        End If
        ds.ReadXml(xtr)

        Return ds
    End Function

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question