我可能會做一些完全錯誤的,但我創建了一個簡單的測試模式:Xsd2Code幫助 - 生成的代碼似乎並不匹配模式
<?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文件的.. 。爲培養我對這個
的Cos
三個問題,沒有標記爲回答。 –