I don't really understand what you are trying to expain....
Here is an example of what i am doing:
This is the xsd:
<xs:element name="Flight" type="Flight"/>
<xs:complexType name="Flight">
<xs:sequence>
<xs:element name="DepartureDate" type="xs:date" />
<xs:element name="Origin" type="xs:string" />
<xs:element name="Destination" type="xs:string" />
<xs:element name="OutOfStock" type="OutOfStock" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="FlightNo" type="xs:string" />
<xs:attribute name="LegIndex" type="xs:int" />
</xs:complexType>
<xs:complexType name="OutOfStock">
<xs:sequence>
<xs:element name="Product" type="xs:int" />
<xs:element name="Row" type="xs:string" />
</xs:sequence>
</xs:complexType>
Here is when i fill the dataset:
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"E:\Schema.xsd");
SqlConnection conn = getConnection;
SqlDataAdapter da = new SqlDataAdapter("select * from
vFlights", conn);
da.Fill(ds, "Flight");
ds.WriteXml("flights.xml");
My problem is that the "OutOfStock" element doesn't show, it just shows the
"Product" and "Row" but there are not nested inside the "OutOfStock" tag. I
look at the schema generated after with a ds.WriteXMLSchema(".."); and it
seemed to take into consideration the specified schema but it also overloaded
with its owe...
It generated this:
<Flight FlightNo="222" LegIndex="1">
<DepartureDate>2006-07-25</DepartureDate>
<Origin>RRR</Origin>
<Destination>GGG</Destination>
<Row>23</Row>
<Product>1</Product>
</Flight>
But i want it to generate this:
<Flight FlightNo="222" LegIndex="1">
<DepartureDate>2006-07-25</DepartureDate>
<Origin>RRR</Origin>
<Destination>GGG</Destination>
<OutOfStock>
<Row>23</Row>
<Product>1</Product>
</OutOfStock>
</Flight>
thanks, maybe this will clarify things!
"rhaazy" wrote:
You may be approaching this the wrong way, I recently had a problem
going from a dataset to xml and found the columnmapping property of the
dataset in combination with relation objects to work very well
for example:
ds.Relations.Add(new DataRelation("Appsettings AConfiguration",
ds.Tables["Appsettings"].Columns[0],
ds.Tables["AConfiguration"].Columns[0]));
ds.Relations.Add(new DataRelation("Profile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configuration"].Columns[1]));
ds.Relations[0].Nested = true;
ds.Relations[1].Nested = true;
ds.Tables["Appsettings"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["AConfiguration"].Columns[3].ColumnMapping =
MappingType.SimpleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[0].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[1].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[2].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[3].ColumnMapping =
MappingType.Attribute ;
ds.Tables["Configuration"].Columns[4].ColumnMapping =
MappingType.SimpleContent ;
the relation objects create the parent child relationship between the
columns, and the nesting property sets it up for use in your XML
document.
the columnmapping stuff is pretty self explanatory.
Hope this helps.
Eric wrote:
Help! I created a XML schema with a Visual Studio tools. I'm filling a
dataset with a DataAdapter. Before I use the "WriteXml" method to write the
data to a xml file, I want to map the XSD file I created to the dataset so
that when I do use the "WriteXml" method, the generated xml file will be
properly formatted to the schema I created. I did try using the
"ReadXMLSchema" but it didn't work. Please help me!