将xml元素和节点反序列化为字符串属性

时间:2015-06-17 09:49:44

标签: c# xml serialization

我有以下xml

  <Amendment.Text>
    <Page>4</Page>
    <Line>4</Line>
    <Bold>It is a </Bold>   
    <Italic>Beautiful Day</Italic>
    <Bold>In London</Bold>
    <Italic>17 June 2015</Italic>   
</Amendment.Text>

我想将<Bold><Italic>元素检索到 字符串属性

输出(字符串属性内容):

<Bold>It is a </Bold>   
    <Italic>Beautiful Day</Italic>
    <Bold>In London</Bold>
    <Italic>17 June 2015</Italic>

我的可序列化类如下 -

[Serializable]
    public class AmdTextType
    {

        public string Page { get; set; }

        public string Line { get; set; }

        public string Content { get; set; }

    }

我能够反序列化PageLine但无法获得 带有标记

ItalicBold元素

1 个答案:

答案 0 :(得分:2)

这可能不是:

  <Amendment.Text>
    <Page>4</Page>
    <Line>4</Line>
    <Content>CDATA(["
       <Bold>It is a </Bold>   
       <Italic>Beautiful Day</Italic>
       <Bold>In London</Bold>
       <Italic>17 June 2015</Italic>   
    "])
    </Content>
</Amendment.Text>