We help IT Professionals succeed at work.
Get Started

Add XML Node using another XML file

495 Views
Last Modified: 2013-12-17
I have 3 xml files which is stored in one location. I want to add all these 3 XML into one XML file with different node name. I could get the XML values as string using XMLTextWriter and StringWriter; but adding to the new xml as node with this string is causing problems. The following :

 Private Sub btnXMLtoStr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXMLtoStr.Click

        Dim strXML As String

        Dim oXML As New XmlDocument()
        Dim oRoot As XmlNode
        Dim oNode As XmlNode
        Dim oDB As XmlNode
        Dim oTable As XmlNode

        oRoot = oXML.CreateElement("WindcatcherSettings")
        oNode = oXML.AppendChild(oRoot)

        oDB = oXML.CreateElement("ThresholdXML")
        strXML = GetXMLString("C:\Thresholds.xml")

        oNode.AppendChild(oDB)

        oTable = oXML.CreateElement(strXML)
        oDB.AppendChild(oTable)

        oXML.Save("C:\AllSettings.xml")
    End Sub


    Private Function GetXMLString(ByVal XMLPath As String) As String

        Dim xmlDoc As New XmlDocument()
        Dim sw As New StringWriter()
        Dim sVal As String


        Try
            xmlDoc.Load(XMLPath)
            Dim xw As New XmlTextWriter(sw)
            xmlDoc.WriteTo(xw)
            sVal = sw.ToString()
        Catch ex As Exception

        End Try

        GetXMLString = sVal
    End Function

Error is thrown on link         oTable = oXML.CreateElement(strXML)

After writing is it possible to retrieve all the node values as string? Say I want to search for "ThresholdXML" and get all the node values as String? Please help

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE