How do I: Insert text in an XML document?

  • Thread starter Thread starter name
  • Start date Start date
N

name

Say I have an xml document called test.xml
that looks like this:

<?xml version="1.0"?>
<!--test.xml-->
<theroot>
<group_a>
<stuff>This</stuff>
<stuff>is</stuff>
<stuff>a</stuff>
<stuff>test</stuff>
</group_a>
<group_b>
</group_b>
</theroot>


And I want to insert some stuff in group_b, what would be the easiest
way of doing this?

Thanks in Advance,
Chris
 
Say I have an xml document called test.xml
that looks like this:

<?xml version="1.0"?>
<!--test.xml-->
<theroot>
<group_a>
<stuff>This</stuff>
<stuff>is</stuff>
<stuff>a</stuff>
<stuff>test</stuff>
</group_a>
<group_b>
</group_b>
</theroot>


And I want to insert some stuff in group_b, what would be the easiest
way of doing this?

Thanks in Advance,
Chris
XmlDocument class should suit your needs Chris.

XmlDocument doc = new XmlDocument();

doc.Load("{path to}\\test.xml");

XmlNode child = doc.SelectSingleNode("/test/group_b");

And you will be able to edit the node and its properties directly... :)

Dont forget to also call .Save() on the document when your done.

Tam
 
Back
Top