2015-02-10 99 views
0

我不明白为什么只有元素的第一个“内部节点”被反序列化为model.Description。我如何需要设置C#Body类的Description节点,以便将介于和之间的所有文本分配给Description元素?为什么整个<description>节点没有被反序列化?

代码:

class Program 
{ 
    static void Main(string[] args) 
    { 
     try 
     { 
      var xDoc = XDocument.Load("xmlModel.xml"); 
      model.Body model = null; 
      var xmlSerializer = new XmlSerializer(typeof(model.Body)); 
      using (var reader = xDoc.CreateReader()) 
      { 
       model = (model.Body)xmlSerializer.Deserialize(reader); 
      } 

      Console.Write(model.Description); 

     } 
     catch (System.Xml.XmlException e) 
     { 
      Trace.TraceWarning("XML Parse Error: xmlModel.xml, line " + e.LineNumber + ", position " + e.LinePosition + "\n" + e.Message); 
     } 
    } 
} 

型号:

namespace model 
{ 
    [XmlRoot("body")] 
    public class Body 
    { 
     [XmlElement("description")] 
     public String Description { get; set; } 

     [XmlElement("address")] 
     public String UnitAddress { get; set; } 
    } 
} 

XML:

<?xml version="1.0" encoding="utf-8" ?> 
    <body> 
     <description> 
      <p>The PGT has 10 user-accessible 32-bit registers, which are used to configure, 
operate, and monitor the state of the PGT. 
</p> 
<p> 
    An IP bus write access to the PGT Control Register (PGT_CR) and the GPT Output Compare 
    Register1 (PGT_OCR1) results in <i>one cycle of wait state</i><ph audience="internal"> (ips_xfr_wait high for 1 cycle)</ph>, while other valid IP bus accesses incur 0 
    wait states. 
</p> 
<p> 
    Irrespective of the Response Select <ph audience="internal">(resp_sel) </ph>signal 
    value, a Write access to the PGT Status Registers (Read-only registers PGT_ICR1, 
    PGT_ICR2, PGT_CNT) will generate a bus exception<ph audience="internal"> (ips_xfr_err signal will be asserted)</ph>. 
</p> 
<ul> 
    <li> 
    If the Response Select <ph audience="internal">(resp_sel) </ph>signal is driven Low, then the Read/Write access to the <i>unimplemented</i> address space of PGT (<i>ips_addr</i> is greater than or equal to $BASE + $028) will generate a bus exception<ph audience="internal"> (ips_xfr_err signal will be asserted)</ph>. 
    </li> 
    <li> 
    If the Response Select <ph audience="internal">(resp_sel) </ph>is driven High, then the Read/Write access to the unimplemented address space of PGT will <i>not</i> generate any error response (like a bus exception). 
    </li> 
</ul> 
    </description> 
    <address>0x0000</address> 
</body> 

由于一吨, 克里斯

+0

的全部内容? IE:在你的测试中,什么是分配给描述? – Vlad274 2015-02-10 21:56:08

+0

说明在您的示例x​​ml中显示的两次出现中都没有内部文本。 – 2015-02-10 21:57:28

+0

我看到实际上只有一个。无论如何,它不包含任何内部文本,只包含子节点。 – 2015-02-10 21:59:30

回答

0

请加上<description><![CDATA[... ]]></description>一个围绕您的描述数据。

然后你就可以当你说“第一内部节点”你是什么意思提取与model.Description

相关问题