[英]InnerText XmlNode C#
I am trying to create an XMLDocument in C#. 我正在尝试在C#中创建XMLDocument。 This is the file that I am trying to parse.
这是我要解析的文件。
<root>
<child/>
some text here
</root>
However, when I try to assign the "some text here" to the element, I run into a problem. 但是,当我尝试将“此处的某些文本”分配给元素时,我遇到了问题。 In the beginning I have the XmlNode's
一开始我有XmlNode
InnerText=""
and the XmlNode's 和XmlNode的
InnerXml=</child>
By doing 通过做
node.InnerText+="some text here";
my 我的
InnerXml="";
I do not understand what am I doing wrong. 我不明白我在做什么错。
Note If I have the following XML - where the text comes before the child, I have no issues.
注意:如果我有以下XML-文本在子级之前,则没有问题。
<root>
some text here
<child/>
</root>
Rather than trying to manipulate the XML by changing the InnerXxx
properties, you should do it by invoking AppendChild
. 与其尝试通过更改
InnerXxx
属性来操纵XML,还应该通过调用AppendChild
。
You'd want to append an XmlText
element as a new child. 您想将
XmlText
元素附加为新的子元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.