XML構造のクラスモデルがあります。ここでは、xmlを解析します。 私はXSDジェネレータを使用しました。すべてがうまくいくが、2つのことはうまくいかない。解析するXMLクラス
まず:私はいくつかの文字列ことを得ることができます私のメッセージクラスの任意のフィールドを持っていないXSD発生器から得た
<protocol>
<!-- an error message which may appear from both sides as a response anytime.-->
<message type="error">
some string
</message>
...
</protocol>
私のクラスのセット:私は、XMLでそのような何かを持っています。私はそのクラスで作成したフィールドにどのような属性を割り当てる必要がありますか:この値を取得するための(文字列メッセージ)?
第二:私は、XMLのそのようなものがあります。
<message type="gameState">
<gameId id="zxcc"/>
<!-- one tag of the two below appears in message -->
<nextPlayer nick="asdd"/>
<gameOver>
<!-- this tag appears repeatedly for all the players -->
<player nick="zxc" result="winner"/>
</gameOver>
<!-- this tag will always appear. Not read by the server.-->
<gameState>
</gameState>
</message>
と発電機をゲームオーバーのメッセージクラスでこれを作成します。
/// <remarks/>
[System.Xml.Serialization.XmlArrayAttribute("gameOver", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("player", typeof(player), IsNullable=false)]
public player[][] gameOver {
get {
return this.gameOverField;
}
set {
this.gameOverField = value;
}
}
を、私は例外を取得:
Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'player[]' to 'player'
error CS0029: Cannot implicitly convert type 'player' to 'player[]'
playerはジェネレータによって定義されたクラスですが、他の属性でも動作します。私はこの断片xmlが複雑なノードであることがわかります。ここでは3度です。
どうすればこの問題を解決できますか?
良い考えは、これを受け入れられた回答としてマークすることです... –