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:complexTy pe name="Flight">
<xs:sequence>
<xs:element name="Departure Date" type="xs:date" />
<xs:element name="Origin" type="xs:string " />
<xs:element name="Destinati on" type="xs:string " />
<xs:element name="OutOfStoc k" type="OutOfStoc k" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="FlightNo" type="xs:string " />
<xs:attribute name="LegIndex" type="xs:int" />
</xs:complexType>
<xs:complexTy pe name="OutOfStoc k">
<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.ReadXmlSchem a(@"E:\Schema.x sd");
SqlConnection conn = getConnection;
SqlDataAdapter da = new SqlDataAdapter( "select * from
vFlights", conn);
da.Fill(ds, "Flight");
ds.WriteXml("fl ights.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.WriteXMLSche ma(".."); 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>GG G</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>GG G</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.Ad d(new DataRelation("A ppsettings AConfiguration" ,
ds.Tables["Appsetting s"].Columns[0],
ds.Tables["AConfiguration "].Columns[0]));
ds.Relations.Ad d(new DataRelation("P rofile Configuration",
ds.Tables["Profile"].Columns[0],
ds.Tables["Configurat ion"].Columns[1]));
ds.Relations[0].Nested = true;
ds.Relations[1].Nested = true;
ds.Tables["Appsetting s"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["AConfiguration "].Columns[3].ColumnMapping =
MappingType.Sim pleContent ;
ds.Tables["Profile"].Columns["ID"].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[0].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[1].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[2].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[3].ColumnMapping =
MappingType.Att ribute ;
ds.Tables["Configurat ion"].Columns[4].ColumnMapping =
MappingType.Sim pleContent ;
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
"ReadXMLSch ema" but it didn't work. Please help me!