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

Avatar of undefined
Last Comment
ZekeLA

8/22/2022 - Mon
muhammadyasir

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

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

ASKER
A developer friend of mine gave me the solution. I'll post it if it's not proprietary.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
ZekeLA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.