Solved

Consuming XML from a SQL server 2008 stored proc

Posted on 2013-10-22
2
285 Views
Last Modified: 2013-10-23
I am looking for a good guide or article that demonstrates how to consume XML from a SQL server 2008 stored proceedure

A simplified version of the stored proc
SELECT    UserName
		,Forename
		,Surname
		,Email 
FROM dbo.UserDetails 
FOR XML RAW, ELEMENTS;

Open in new window


and a samle of the XML returned

<row>
  <UserName>preinvoiceca</UserName>
  <Forename>Detached Invoice</Forename>
  <Surname>Processor CA</Surname>
  <Email>preinvoiceca@trailers.com</Email>
</row>
<row>
  <UserName>preinvoiceusa</UserName>
  <Forename>Detached Invoice</Forename>
  <Surname>Processor USA</Surname>
  <Email>preinvoiceusa@trailers.com</Email>
</row>

Open in new window

0
Comment
Question by:Alyanto
[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 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39591562
Some examples with different techniques are posted in following link

http://developer.yahoo.com/dotnet/howto-xml_vb.html

You can also convert it to a dataset

http://www.nullskull.com/faq/1889/convert-an-xml-string-into-a-dataset.aspx


Public Shared Function XMLToDataSet(ByVal xmlStr As String, ByVal schemaFile As String) As DataSet
        'Convert the XML to a dataset
        Dim sr As New StringReader(xmlStr)

        'Convert xmlData to a Dataset
        Dim ds As New DataSet

        If schemaFile = String.Empty Then
            ds.ReadXml(sr, XmlReadMode.InferSchema)
        Else
            ds.ReadXmlSchema(schemaFile)
            ds.ReadXml(sr, XmlReadMode.ReadSchema)
        End If

        For Each relation As DataRelation In ds.Relations
            For Each c As DataColumn In relation.ParentColumns
                If Not relation.ChildTable.Columns.Contains(c.ColumnName) Then
                    relation.ChildTable.Columns.Add(c)
                End If
                For Each dr As DataRow In relation.ChildTable.Rows
                    dr(c.ColumnName) = dr.GetParentRow(relation)(c.ColumnName)
                Next
            Next
        Next

        Return ds
    End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:Alyanto
ID: 39593348
Spot on, and timely too :)

/Aly
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
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.

635 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