C# 对子innertext的XML访问

C# 对子innertext的XML访问,c#,.net,xml,innertext,C#,.net,Xml,Innertext,我有以下XML: <location> <character name="name" mask="pap.png" X="397" Y="60"> <look reaction="False"> text1 <answer>text2</answer> </look> <talk xml=""/> </character> </locati

我有以下XML:

<location>
  <character name="name" mask="pap.png" X="397" Y="60">
    <look reaction="False">
      text1
      <answer>text2</answer>
    </look>
    <talk xml=""/>
  </character>
</location>
之后,我的XML看起来像:

<location>
  <character name="name" mask="pap.png" X="397" Y="60">
    <look reaction="False">text1</look>
    <talk xml=""/>
  </character>
</location>

文本1

因此它切断了
子对象。有什么想法吗?

您必须更改
InnerXml
。因为您的XML是混合复杂类型(Complex Type=Mixed:XML元素可以包含属性、元素和文本),并且DOM不完全了解这些属性、元素和文本。您的代码可以如下所示:

node.ChildNodes[0].InnerXml = "new_text1 <answer>new_text2</answer>";
node.ChildNodes[0].InnerXml=“new\u text1 new\u text2”;

如果这是行
节点.ChildNodes[0].InnerText=“new\u text1”

取代

<look reaction="False">
      text1
      <answer>text2</answer>
    </look>

文本1
文本2
那么您已经从中替换了标签
text2

<look reaction="False">
      text1
      <answer>text2</answer>
    </look>