Solved

Add/Change Root Node in XML file

Posted on 2001-07-27
4
174 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
[X]
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
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using Access 8 93
Export Data to Different .csv Files 27 133
Set WorkSheet  not Working 9 62
Get the Y value of a line at X in a chart in VBA 28 73
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

739 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