Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Add/Change Root Node in XML file

Posted on 2001-07-27
4
172 Views
Last Modified: 2008-02-01
Dave Green - How can we make the root node something other than <order><\order>. I need Order and its children to be nodes. Remember you provided the following:

Option Explicit

Dim oDOM      As DOMDocument
Dim oRoot     As IXMLDOMNode
Dim oNode     As IXMLDOMNode
Dim oNodeList As IXMLDOMNodeList

Private Sub Command1_Click()

 Set oDOM = New DOMDocument
 Dim i As Long
 Dim strName As String
 Dim strXML As String
 
 Dim dblQ As String
 dblQ = Chr(34) 'double quotes
 
 oDOM.Load "C:\One.xml"

 Set oRoot = oDOM.selectSingleNode("export_data")
 
 Set oNodeList = oRoot.selectNodes("order")
 
 MsgBox oNodeList.Length
 
 For i = 0 To oNodeList.Length - 1
   Dim oNewDOM As New DOMDocument
   Set oNode = oNodeList.Item(i)
   strXML = "<?xml version=" & dblQ & "1.0" & dblQ & "?>" & oNode.xml
   Set oNode = oNode.selectSingleNode("quote_number")
   strName = oNode.Text
   With oNewDOM
     .loadXML strXML
     .Save "C:\Temp\Order" & strName & ".xml"
   End With
 Next
 
End Sub

Private Sub Form_Unload(Cancel As Integer)
 Set oDOM = Nothing
 Set oNode = Nothing
 Set oNodeList = Nothing
End Sub


Thanks!
0
Comment
Question by:cgrexer
  • 3
4 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6327855
Just make this change

For i = 0 To oNodeList.Length - 1
  Dim oNewDOM As New DOMDocument
  Set oNode = oNodeList.Item(i)
  strXML = "<?xml version=" & dblQ & "1.0" & dblQ & "?>" & "<ROOTNODEHERE> oNode.xml
  Set oNode = oNode.selectSingleNode("quote_number")
  strName = oNode.Text & "</ROOTNODEHERE>
  With oNewDOM
    .loadXML strXML
    .Save "C:\Temp\Order" & strName & ".xml"
  End With
Next
0
 
LVL 8

Accepted Solution

by:
Dave_Greene earned 100 total points
ID: 6327898
Oops... Brain Slip...  

For i = 0 To oNodeList.Length - 1
 Dim oNewDOM As New DOMDocument
 Set oNode = oNodeList.Item(i)
 strXML = "<?xml version=" & dblQ & "1.0" & dblQ & "?>" & "<ROOTNODEHERE>" & oNode.xml & "</ROOTNODEHERE>"
 Set oNode = oNode.selectSingleNode("quote_number")
 strName = oNode.Text
 With oNewDOM
   .loadXML strXML
   .Save "C:\Temp\Order" & strName & ".xml"
 End With
Next
0
 

Author Comment

by:cgrexer
ID: 6328013
Dave -

You da' man! Thanks again and sorry for misspelling your last name.

Grant
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6328152
Anytime, Have a great weekend Gran

Just Kidding  :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question