1. 아별툴
  2. 아별툴 패밀리
  3. 엑셀 질문하기
  4. 엑셀 강좌
  5. 엑셀 팁
  6. 엑셀 자료실
  7. 엑셀 연구과제
  8. 엑셀 북마크
  9. 관련 프로그램 소개

[레벨:30]아별

2015.04.13 19:16

아래와 같이 접근하는 것도 참고해보자..

출처 : 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



친절하게도.. 변경 후에 꼭 저장하라는 코멘트도 잊지 않고 남겨줌..

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")



문서 첨부 제한 : 0Byte/ 2.00MB
파일 제한 크기 : 2.00MB (허용 확장자 : *.*)