[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to user Dataset ReadXMLSchema from XML String without XSD File

Posted on 2010-09-04
4
Medium Priority
?
1,187 Views
Last Modified: 2013-11-08
I have dataset which I used its GetXMLSchema and GetXML methods on. With those string values, how can I load a new dataset with the xml and its schema?

Here's my code so far:

        Dim sXMLSchema As String = SomeDataSet.GetXMLSchema()
        Dim sXML As String = SomeDataSet.GetXML()

        Dim ds As New DataSet
        '   ds.ReadXmlSchema( ??? )   ' What goes here?
        ds.ReadXml(readerXML)

Open in new window


I think I need to convert sXMLSchema to some type of reader but I haven't been able to figure that part out yet. And I don't really want to have to save the schema to an XSD file just to use the ReadXmlSchema(FileName) overload.

Any suggestions on how to do this?

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
  • 3
4 Comments
 
LVL 5

Expert Comment

by:muhammadyasir
ID: 33605953
try this code
private void ReadSchemaFromXmlTextReader ( ) {
   // create the DataSet to read the schema into.
   DataSet thisDataSet = new DataSet ( );
   // set the file path and name. Modify this for your purposes.
   string filename = "mySchema.xml";
   // create a FileStream object with the file path and name.
   System.IO.FileStream myFileStream = new System.IO.FileStream
      ( filename,System.IO.FileMode.Open );
   // create a new XmlTextReader object with the FileStream.
   System.Xml.XmlTextReader myXmlTextReader = 
      new System.Xml.XmlTextReader ( myFileStream );
   // Read the schema into the DataSet and close the reader.
   thisDataSet.ReadXmlSchema ( myXmlTextReader );
   myXmlTextReader.Close ( );
}

Open in new window

0
 
LVL 1

Author Comment

by:ZekeLA
ID: 33606418
Is there any way to do it without creating a file first?

I'm starting with a dataset. I want to pass that dataset using xml through a webservice. The client is not necessarily .NET so I can't / don't want to pass the dataset directly.

Thanks.
0
 
LVL 1

Author Comment

by:ZekeLA
ID: 33606811
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: 33799846
Here's how to do it with streams.
    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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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:…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

656 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