2
我有用于XML结构的类模型,我想在其中解析xml。 我使用了XSD生成器。一切都会好的,但有两件事情不行。用于解析的XML类
第一:我在XML类似的东西:
<protocol>
<!-- an error message which may appear from both sides as a response anytime.-->
<message type="error">
some string
</message>
...
</protocol>
我的类集合这是我从XSD生成了没有我的消息类中的任何领域,我可以得到一些字符串。什么属性,我必须分配给我在该类中创建的字段:(字符串消息)获取此值?
二:我有类似的东西在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>
和发电机在消息该类创建GAMEOVER:
/// <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[]'
播放器是由生成器定义的类,它在其他属性中起作用。我发现这个片段XML只是复杂的节点,我有3度。
我该如何解决这个问题?
一个好主意是将其标记为接受的答案... – 2012-12-10 01:34:29