Solved

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

Posted on 2010-09-05
2
355 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
checkbox group not updating when none of them is selected 11 43
asp.net figure out error 3 41
Multi-Column Repeater 3 37
ASP.NET data base connection 35 81
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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