反序列化Xml并一次获取其字符串版本

时间:2017-09-06 09:18:14

标签: c# xml serialization

我有一个像这样的xml文件:

<root>
    <prop1>
       Here I have some textual contents
       <jump href="go_here.com">some content</jump>
       And some other Text
       <jump href="go_there.com">some other content</jump>
       .
   </prop1>
   <prop2>
      other data
   </prop2>
</root>

我使用一些Serializable类将此xml文件映射到C#对象。 我想在两个版本中反序列化prop1: 一个包含&lt;的列表jump&gt;,另一个将所有xml部分作为字符串包含。

我有一个这样的课程:

[XmlRoot("root")]
public class XmlRoot{

    public class XmlProp1 { get; set;}

    public class XmlProp2 { get; set;}
}

[XmlRoot("prop1")]
public partial class{

    [XmlElement("jump")]
    public XmlJump[] jumps { get; set;}

    //some method to get all the prop1 xml portion as a string
}

public partial class XmlJump{

    [XmlAttribute("href")]
    public string Href { get; set;}

    [XmlText()]
    public string Content { get; set;}
}

此外,对XmlProp1使用[XmlText()]仅返回最后一个内部标记之后的文本(&#34;。&#34;在这种情况下)。

0 个答案:

没有答案