Problems with DATASET.WriteXml: I get two files (XML and XSD)

G

Guest

Hi Newsgroup,

I have a really suspicious problem:

I want to write the data of a Dataset to a XML-File, wich should include
then schema of the data.
For this I'm using the method DATASET.WriteXml("FILENAME" + ".xml" ,
System.Data.XmlWriteMode.WriteSchema).

As result I get two files:
a) XML-File : FILENAME.xml, of course containing the data and a reference to
b)
b) XSD-File : FILENAME_app1.xsd , containing the schema.


When I'm changing the overloaded WriteXml-method to try a work around over a
XMLTextWriter I get the same result.

What can be the reason for this behavior ?
How can I solve this problem ?
How can I get an XML-File with an inline schema ?

Many thanks in advance

Jan
 
C

Cor Ligthert

Jan,

This program
Public Class Example
Public Shared Sub Main()
Dim ds As New DataSet("mydataset")
Dim dt As New DataTable("mydatatable")
ds.Tables.Add(dt)
dt.Columns.Add("mycolumn")
ds.WriteXml("c:\test1\a.xml", XmlWriteMode.WriteSchema)
End Sub
End Class

Gives this result

<?xml version="1.0" standalone="yes"?>
<mydataset>
<xs:schema id="mydataset" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="mydataset" msdata:IsDataSet="true"
msdata:Locale="nl-NL">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="mydatatable">
<xs:complexType>
<xs:sequence>
<xs:element name="mycolumn" type="xs:string" minOccurs="0"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</mydataset

I hope that this helps?

Cor
 
G

Guest

Hello Cor,

thanks for your fast answer.
You have described the right and normal way I think but it not works in my
case.

Different to your description I load the (typed) dataset from the database
by using several SQLDataAdapters because the dataset contains relational data
( and there was no way to retrieve all data via SQL directly).
Then I tried to transfer it like your description
ds.WriteXml("c:\test1\a.xml", XmlWriteMode.WriteSchema), but it does not
work. I always get two files; the xml and the xsd.
Meanwhile I've made some additional investigations and I believe the problem
can be the definition of the underlying schema-definition of the dataset:
The typed dataset is defined by a schema which imports for each table a
complexType from an other schema.

Dataset has Schema DSExample.xsd <-- imports <-- BaseElements.xsd

I now found out that I get within the Result XML-File of the
WriteXml-method the content of the Schema of the dataset (DSExample.xsd )
and within the xsd-File I get the definition of the complexTypes
(BaseElements.xsd).

To be more precise my question must be as follows :

How can I include the base complexTypes into the XML-File too -- OR --
How can I reference to the base types with an public URL, using the
WriteXml-method or another method ?

Many thanks in advance

Jan
 
G

Guest

Good Morning NG,

over night I found out what the problem is and I've built a poor workaround.

Problem Description (Visual Studio NET 2002 / NET Framework 1.1 SP1):
1. You need a Dataset with some tables in a relational structure (example
T1,T2,T3, T1 1:n T2; T1 1:n T3)
2. To define the tables structure built a first Schema (xsd1) which contains
these structures as complexType. (This I made to have only one Schema with
the table definitions and than being able to use it in sevaral datasets and
with different table combinations.) (ctT1, ctT2, ctT3)

3. To construct the dateset build the next Schema (xsd2) whith the
Schema-Generator which imports xsd1.

4. Next fill the Dataset with data.

5. Try to write the Dataset with the Dataset.WriteXml-method to a XML-File
--> Dataset.WriteXml("FILENAME.xml",XmlWriteMode.WriteSchema)

6. As result you get two files:

FILENAME.xml which contains the inline schema of the dataset and the data,
FILENAME_app1.xsd which contains the Schema of xsd1.

Workaround
----------

Instead of using the basic definitions of xsd1, I denormalized and now I'm
using only one Schema for the dataset (xsd2) which contains the table
definitions too.

Maybe someone has a better idea ?

Greetings

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top