Solved

Add/Change Root Node in XML file

Posted on 2001-07-27
4
165 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now