xsd を作成しました:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="test" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Extension">
<xs:complexType>
<xs:sequence>
<xs:element name="parent">
<xs:annotation>
<xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="parentItem">
<xs:complexType>
<xs:sequence>
<xs:element name="child">
<xs:annotation>
<xs:documentation></xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" default="10" name="childItem" type="xs:integer" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
このスキーマを DataSet に読み込み、xml を編集して作成したい
だから私は値100でchildItem要素を埋めようとします:
DataSet a = new DataSet();
a.ReadXmlSchema(mySchema);
a.Tables[3].Rows.Add(100);
それから私は実行します:
a.getXml()
- 結果:
<Extension xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="test">
<childItem xmlns="">100</childItem>
</Extension>
ご覧のとおり、スキーマ関係は完全に無視されます。スキーマでは、childItem の上のすべての親要素が必要であることがわかります。そのため、最も深い子要素に値を追加すると、次のような xml が期待されます。
<Extension>
<Parent>
<ParentItem>
<Child>
<ChildItem>100<ChildItem/>
<Child/>
<ParentItem/>
<Parent/>
<Extension/>
何か不足していますか、それとも DataSet の標準的な動作ですか? どうもありがとう、私はc#とnet4.0、winformsを使用しています