2012-03-13 100 views
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度。

我該如何解決這個問題?

回答

0

好的。我爲我的第一個問題找到解決方案。

我只好一個

[XmlText] 
public string Value { get; set; } 

進去文本中<message></message>,但我不能找到第二個問題的解決方案添加到我的郵件類連載。有什麼想法嗎?

+0

一個好主意是將其標記爲接受的答案... – 2012-12-10 01:34:29