Solved

How to user Dataset ReadXMLSchema from XML String without XSD File

Posted on 2010-09-04
4
1,135 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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