我可能做错了什么,但我创建了一个简单的测试模式:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="MyRoot">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:choice>
<xs:element name="MyChildOne" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice>
<xs:element name="SubChild" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:attribute name="SomeAttribute" type="xs:string"/>
<xs:attribute name="SomethingElse" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="MyChildTwo" type="xs:string" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>
</xs:element>
一个根,两个孩子(一个可选)。
我从 VS2010 运行 Xsd2Code,生成的代码创建了两个“根”类(MyRoot 和 MyChildOne),而没有创建预期的 MyChildTwo。我本来希望有一个带有 MyRoot.MyChildOne 的模型......
这是生成的代码:
using System;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Collections;
using System.Xml.Schema;
using System.ComponentModel;
using System.Collections.Generic;
public partial class MyRoot
{
private List<object> itemsField;
public MyRoot()
{
this.itemsField = new List<object>();
}
public List<object> Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
}
public partial class MyRootMyChildOne
{
private List<object> itemsField;
private string someAttributeField;
private string somethingElseField;
public MyRootMyChildOne()
{
this.itemsField = new List<object>();
}
public List<object> Items
{
get
{
return this.itemsField;
}
set
{
this.itemsField = value;
}
}
public string SomeAttribute
{
get
{
return this.someAttributeField;
}
set
{
this.someAttributeField = value;
}
}
public string SomethingElse
{
get
{
return this.somethingElseField;
}
set
{
this.somethingElseField = value;
}
}
}
我不明白如何将其序列化为有效的(符合模式的)XML 文件...
感谢您在这方面教育我
因数