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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

937 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

8 Experts available now in Live!

Get 1:1 Help Now