Link to home
Start Free TrialLog in
Avatar of ZekeLA
ZekeLAFlag for United States of America

asked on

How to user Dataset ReadXMLSchema from XML String without XSD File

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.
Avatar of muhammadyasir
muhammadyasir
Flag of Pakistan image

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

Avatar of ZekeLA

ASKER

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.
Avatar of ZekeLA

ASKER

A developer friend of mine gave me the solution. I'll post it if it's not proprietary.
ASKER CERTIFIED SOLUTION
Avatar of ZekeLA
ZekeLA
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial