views:

113

answers:

0

Child elements of my data are being written directly off the root element instead of off the element that is their parent in the schema.

My xsd:

<xs:schema xmlns="MyNameSpace" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="MyNameSpace" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
 <xs:import/>
 <xs:element name="DataFile">
  <xs:complexType>
   <xs:sequence>
    <xs:element name="LastUpdatedBy" type="xs:string"/>
    <xs:element name="DateTimeLastUpdate" type="xs:dateTime"/>
    <xs:element name="DataValues" maxOccurs="unbounded">
     <xs:complexType>
      <xs:all>
       <xs:element name="Num1" type="xs:int"/>
       <xs:element name="Num2" type="xs:int"/>
      </xs:all>
     </xs:complexType>
    </xs:element>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

My input file:

<DataFile xmlns="MyNameSpace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="MyNameSpace MySchema.xsd">
 <LastUpdatedBy>Dan</LastUpdatedBy>
 <DateTimeLastUpdate>2009-12-07T16:40:30.0Z</DateTimeLastUpdate>
 <DataValues>
  <Num1>0</Num1>
  <Num2>0</Num2>
 </DataValues>
 <DataValues>
  <Num1>2</Num1>
  <Num2>0</Num2>
 </DataValues>
</DataFile>

What gets saved by MyDataSet.WriteXml(filename)

<DataFile xmlns="MyNameSpace">
 <LastUpdatedBy>Dan</LastUpdatedBy>
 <DateTimeLastUpdate>2009-12-07T16:40:30.0Z</DateTimeLastUpdate>
 <DataValues>
  <Num1>0</Num1>
  <Num2>0</Num2>
 </DataValues>
 <DataValues>
  <Num1>2</Num1>
  <Num2>0</Num2>
 </DataValues>
</DataFile>

The xmlns:xsi and xsi:schemaLocation attributes are not written. What do I need to do to preserve them?