Solved

Add/Change Root Node in XML file

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…
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…

762 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

26 Experts available now in Live!

Get 1:1 Help Now