How to user Dataset ReadXMLSchema from XML String without XSD File

Posted on 2010-09-04
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?

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.
Question by:ZekeLA
  • 3

Expert Comment

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


Author Comment

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.


Author Comment

ID: 33606811
A developer friend of mine gave me the solution. I'll post it if it's not proprietary.

Accepted Solution

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


        End If


        Return ds

    End Function

Open in new window


Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now