views:

168

answers:

1

could anybody help me to write nodes to existing xml file to a particular position using vb.net?

<xml>
  <person>
    <name>a</name>
  </person>
  <person>
    <name>b</name>
  </person>
  <person>
    <name>c</name>
  </person>
  <person>
    <name>d</name>
  </person>
</xml>

here i want to insert a node just after the node person which contains value a for the node name.

<xml>
  <person>
    <name>a</name>
  </person>
  <person>
    <name>e</name>
  </person>
  <person>
    <name>b</name>
  </person>
  <person>
  <name>c</name>
  </person>
  <person>
    <name>d</name>
  </person>
</xml>
A: 

~|Simple Node Addition

To add a new node to an XML file, the XmlNode class provides various methods. To start, an XML file must have a root. This ensures that the file has at least one node. Before adding a new node, you must have a reference of another node. This information will allow you to decide where to position the new node.

To add a new node as a child of an existing node, the simplest position to use is to add the new node at the end of the list of nodes of the existing node. This position is supported by the XmlNode.AppendChild() method. Its syntax is:

Public Overridable Function AppendChild(ByVal newChild As XmlNode) As XmlNode

This method accepts as argument the new node that will be created. This means that you can first "build" an XmlNode object. To do this, you can use a pointer to the type of node you want to create.|~

copied from this

jjj