TheFunOne
TheFunOne

Reputation: 303

InnerText XmlNode C#

I am trying to create an XMLDocument in C#. 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

InnerText="" 

and the XmlNode's

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.

<root>
 some text here
 <child/>
</root>

Upvotes: 0

Views: 395

Answers (1)

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239636

Rather than trying to manipulate the XML by changing the InnerXxx properties, you should do it by invoking AppendChild.

You'd want to append an XmlText element as a new child.

Upvotes: 2

Related Questions