shanvidhya
asked on
Add XML Node using another XML file
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("Windca tcherSetti ngs")
oNode = oXML.AppendChild(oRoot)
oDB = oXML.CreateElement("Thresh oldXML")
strXML = GetXMLString("C:\Threshold s.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
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("Windca
oNode = oXML.AppendChild(oRoot)
oDB = oXML.CreateElement("Thresh
strXML = GetXMLString("C:\Threshold
oNode.AppendChild(oDB)
oTable = oXML.CreateElement(strXML)
oDB.AppendChild(oTable)
oXML.Save("C:\AllSettings.
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
http://www.geekpedia.com/tutorial150_How-to-copy-XML-nodes-between-documents.html
>> Error is thrown on link oTable = oXML.CreateElement(strXML)
can you try this?
can you try this?
'Create a document fragment.
Dim docFrag As XmlDocumentFragment = doc.CreateDocumentFragment()
'Set the contents of the document fragment.
docFrag.InnerXml = strXML
'Add the children of the document fragment to the
'original document.
oDB.AppendChild(docFrag)
ASKER
Roshmon,
It throws Invalid Operation exception at oDB.AppendChild(docFrag)
It throws Invalid Operation exception at oDB.AppendChild(docFrag)
ASKER
Roshmon,Following is the xml file I am trying to use
SourceDoc.xml
SourceDoc.xml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The following line of code solve the problem:
sVal = xmlDoc.SelectSingleNode("i DENEventXM L").InnerT ext;
Roshmon solution partly solved the problem. So 50% points can go to Roshmon
Thanks,
Shan
sVal = xmlDoc.SelectSingleNode("i
Roshmon solution partly solved the problem. So 50% points can go to Roshmon
Thanks,
Shan