I have class model for XML structure, where i want parse xml into it.
I used XSD generator. Everything will be fine, but two things don’t work.
First: I have something like that in xml:
<protocol>
<!-- an error message which may appear from both sides as a response anytime.-->
<message type="error">
some string
</message>
...
</protocol>
My class set which i got from xsd generator doesn’t have any field in my message class where i can get that some string. What attribute i have to assign to field which i create in that class: (string message) for getting this value?
Second: I have something like that in 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>
And generator create in message class this for 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;
}
}
And i get exception:
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 is class defined by generator, it works in other attributes. I find that this fragment xml is only complex node where i have 3 degree.
How can i fix this?
Ok. I find solution for my first problem.
I had to add a
to my Message class for serialize into it text within
<message></message>but i can’t find solution for second problem. Any thoughts?