私の XSD には、次のようなものがあります。
<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns:jump="testThingy" elementFormDefault="qualified" targetNamespace="testThingy" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="command" type="jump:commandType" />
<complexType name="loginType">
<sequence>
<element name="userName" />
</sequence>
</complexType>
<complexType name="commandType">
<sequence>
<choice>
<element name="login" type="jump:loginType" />
<element name="logout" />
</choice>
<!-- There are other elements here but they are IRRELEVANT to the question -->
</sequence>
</complexType>
</schema>
したがって、XSD to C# ツール (xsd.exe または Xsd2Code) を使用すると、2 つのクラス (commandType と loginType) が生成されます。しかし、d にログアウト コマンドを送信させるには、XML を次のようにする必要があります。
<command>
<logout />
</command>
しかし、私は- logoutTypeに相当するものは何も持っていません。生成されたクラスで、ログアウトを使用する場合、commandType は「XmlElement」を想定しています。
XSD から C# へのツールがこのクラスを生成できないと仮定すると、基本的に単純にシリアライズするだけで XmlElement 型のクラスを作成して、commandType に適合させるにはどうすればよいでしょうか?
(注:XSDを制御することはできません。そうでなければ、新しいcomplexTypeを含めるように変更していたでしょう)