0 Replies Latest reply on Sep 9, 2015 6:00 AM by aviR

    problem appending xml element and attribute to existing file

    aviR Level 1

      hello all,

      I have a xml file which looks something like this:

      <root>

      <element1 attr1=""attr2=""attr3="">message</element>

      <element1 attr1=""attr2=""attr3="">message</element>

      </root>

       

      I want to append "<element1 attr1=""attr2=""attr3="">message</element>" to the document.

      I am using the code:

       

      Dim xdoc As New XmlDocument()

      xdoc.Load(xfile)

      Dim xerr As System.Xml.XmlElement = xdoc.CreateElement("element1")

      Dim xatttr1 As System.Xml.XmlAttribute = xdoc.CreateAttribute("attr1")

      xatttr1.Value = ""

      xerr.Attributes.Append(xatttr1)

      Dim xatttr2 As System.Xml.XmlAttribute = xdoc.CreateAttribute("attr2")

      xatttr2.Value = ""

      xerr.Attributes.Append(xatttr2)

      Dim xatttr3 As System.Xml.XmlAttribute = xdoc.CreateAttribute("attr3")

      xatttr3 .Value = ""

      xerr.Attributes.Append(xatttr3 )

      end function()

       

      But this is not giving any output or error. My xml file is left as it is.

      Please tell me where and what is going wrong?

      Please help.

      thanks