Just how you deal with the data in your macro is up to you. But this should get you started. BTW, if you want to write data to your xml file, use something like: myItem.Attributes.getNamedItem("firstname").Text = "Hello, sailor!"
At the end of your macro, put a: myXMLDocument.save("C:\temp\SomeOtherName.xml")
아래와 같이 접근하는 것도 참고해보자..
출처 : http://www.experts-exchange.com/Software/Office_Productivity/Q_24186814.html
XML file:
<?xml version="1.0"?>
<MyGroups>
<GROUPS>
<TITLE title= "Group 1">
<ITEM firstname="Jane" surname="Wilson" maritalstatus="single"/>
<ITEM firstname="Susan" surname="Jones" maritalstatus="divorced"/>
<ITEM firstname="Amanda" surname="Roberts" maritalstatus="married"/>
</TITLE>
<TITLE title= "Group 2">
<ITEM firstname="Juliet" surname="Stephens" maritalstatus="single"/>
<ITEM firstname="Anne" surname="Lewis" maritalstatus="single"/>
<ITEM firstname="Lorraine" surname="Pearson" maritalstatus="married"/>
<ITEM firstname="Karen" surname="Fielding" maritalstatus="divorced"/>
</TITLE>
</GROUPS>
</MyGroups>
VBA Code:
Option Explicit
Sub ShowMyXML()
Dim myXMLDocument As New DOMDocument30
Dim myTitles As IXMLDOMNodeList
Dim myTitle As IXMLDOMNode
Dim myItems As IXMLDOMNodeList
Dim myItem As IXMLDOMNode
myXMLDocument.Load ("C:\Temp\DelMar.xml")
Set myTitles = myXMLDocument.SelectNodes("//TITLE")
For Each myTitle In myTitles
Debug.Print myTitle.Attributes.getNamedItem("title").Text
Set myItems = myTitle.SelectNodes("//ITEM")
For Each myItem In myItems
Debug.Print myItem.Attributes.getNamedItem("firstname").Text & " | " & _
myItem.Attributes.getNamedItem("surname").Text & " | " & _
myItem.Attributes.getNamedItem("maritalstatus").Text
Next myItem
Next myTitle
End Sub
myItem.Attributes.getNamed
At the end of your macro, put a:
myXMLDocument.save("C:\tem