2011-01-05 71 views
1

我有以下元素獲取的XmlElement內文本和屬性

<Bildfile typ="A" seq="1" width="320" height="214">How_Can_I_Get_This?</Bildfile> 

,我想要得到的元素的innerText和屬性。

具有下列代碼的屬性爲我提供了屬性,但是如何獲取元素的innerText?

我這個

[XmlElement(ElementName = "Bildfile")] 
public Bildfile Image { get; set; } 

[Serializable] 
public class Bildfile 
{ 
    [XmlAttribute(AttributeName = "typ")] 
    public string Type { get; set; } 

    [XmlAttribute(AttributeName = "seq")] 
    public string Sequence { get; set; } 

    [XmlAttribute(AttributeName = "width")] 
    public string Width { get; set; } 

    [XmlAttribute(AttributeName = "height")] 
    public string Height { get; set; } 
} 

感謝試過

回答

1

您需要添加一個屬性與XmlText屬性到你的班級:

[Serializable] 
public class Bildfile 
{ 
    [XmlAttribute(AttributeName = "typ")] 
    public string Type { get; set; } 

    [XmlAttribute(AttributeName = "seq")] 
    public string Sequence { get; set; } 

    [XmlAttribute(AttributeName = "width")] 
    public string Width { get; set; } 

    [XmlAttribute(AttributeName = "height")] 
    public string Height { get; set; } 

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

現在,在反序列化之後,您應該能夠從Value屬性中讀取內部文本。

+0

謝謝marc_s。有用 :) – StrouMfios 2011-01-05 12:52:04