Hi,
I've tested out extracting XML from an empty DataSet and am successful
using the following code:
Dim myXMLfile As String = "c:\mySchema.xml"
Dim con As New SqlConnection(myConnectionString)
Dim daCust As New SqlDataAdapter(mySelectQuery, con)
Dim ds As New DataSet()
daCust.Fill(ds, "Cust")
Dim myFileStream As New System.IO.FileStream _
(myXMLfile, System.IO.FileMode.Create)
Dim MyXmlTextWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
Try
'Write the XML along with the inline schema (default).
ds.WriteXml(MyXmlTextWriter, XmlWriteMode.WriteSchema)
'Write the XML only.
'ds.WriteXml(MyXmlTextWriter, XmlWriteMode.IgnoreSchema)
'Write the XML as a DiffGram.
'ds.WriteXml(MyXmlTextWriter, XmlWriteMode.DiffGram)
MsgBox("Save complete")
Catch ex As Exception
MessageBox.Show(ex.ToString())
Finally
MyXmlTextWriter.Close()
myFileStream.Close()
End Try
The XML file looks like the following:
- <NewDataSet>
- <xs:schema id="NewDataSet" xmlns=""
xmlns:xs="
http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true">
- <xs:complexType>
- <xs:choice maxOccurs="unbounded">
- <xs:element name="Cust">
- <xs:complexType>
- <xs:sequence>
<xs:element name="CustomerID" type="xs:string" minOccurs="0" />
<xs:element name="CompanyName" type="xs:string" minOccurs="0" />
<xs:element name="ContactName" type="xs:string" minOccurs="0" />
<xs:element name="ContactTitle" type="xs:string" minOccurs="0" />
<xs:element name="Address" type="xs:string" minOccurs="0" />
<xs:element name="City" type="xs:string" minOccurs="0" />
<xs:element name="Region" type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="Country" type="xs:string" minOccurs="0" />
<xs:element name="Phone" type="xs:string" minOccurs="0" />
<xs:element name="Fax" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</NewDataSet>
Hope this information is helpful.
Regards,
Harold Ommert
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.