如何使用vba从每个父节点读取子节点并将它们写入excel

时间:2016-02-13 15:37:51

标签: xml excel vba excel-vba xml-parsing

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Root Signature="{5DCBAC3B-D39C-497C-9BE8-744CBADD37AA}" NameVersion="4" Cookie="3447">
    <LogicalNodes Name="Aliases" Owner="{BE401E45-B2D6-4FBA-931A-C2117D5C51AD}">
            <Child0 Name="wndProgman" Owner="{AE704EB6-AD19-45EA-B496-41A5981E8412}">
                <Child0 Name="SHELLDLL_DefView" Owner="{610947DD-D55F-4A13-9CA5-E9088894FD86}">
                    <Child0 Name="FolderView" Owner="{15A15A12-D939-4C0A-8977-BAFAB4D04F43}" />
                </Child0>
            </Child0>
            <Child1 Name="wndShell_TrayWnd" Owner="{DAE8A331-ACA7-4945-8331-7A11E81306D0}">
                <Child0 Name="ReBarWindow32" Owner="{8DD1A6A4-CE21-47EB-B42E-30D5CF347E59}">
                    <Child0 Name="MSTaskSwWClass" Owner="{94EDC32F-6134-4847-870A-844B98B33ACC}">
                        <Child0 Name="MSTaskListWClass" Owner="{8816439D-7900-4047-B0C4-22DD7E60729C}" />
                    </Child0>
                </Child0>
            </Child1>
        </Child0>
        <Child1 Name="notepad" Owner="{449D4FD4-389C-4BEE-BCC2-8A6EC8BC73AB}">
            <Child0 Name="wndNotepad" Owner="{40D93496-0E10-4091-AC8E-9E6E476333FC}">
                <Child0 Name="Edit" Owner="{E0844148-8BB1-43B9-914E-4237ABEE2EC4}" />
            </Child0>
        </Child1>
        <Child2 Name="PorticoVT" Owner="{3EFC33EE-8634-4970-875C-F3BDEA8FA0EB}">
            <Child0 Name="wnd_HeartLandPortico" Owner="{62D04395-D5E2-42A4-8B36-5619A5B4AB6F}">
                <Child0 Name="browser_HeartLandPortico" Owner="{F5CB4FF9-DC18-4D49-B2CB-A31D82F60AEA}">
                    <Child0 Name="page_PorticoLogin" Owner="{AB2707EF-D4C1-43A7-B0F1-198CE11141D5}">
                        <Child0 Name="txt_LoginUserName" Owner="{EB0E205E-1832-4208-9957-D847514AFA9F}" />
                    </Child0>
                    <Child1 Name="page_PorticoHome" Owner="{AB2707EF-D4C1-43A7-B0F1-198CE11141D5}">
                        <Child0 Name="cmb_Sites" Owner="{4354AEA8-183E-47EA-95D8-D37C04E571EB}" />
                        <Child1 Name="cmb_Devices" Owner="{A5BFE04E-C3AB-4D76-ACCE-E0183FE6CB6C}" />
                        <Child2 Name="menu_Popup" Owner="{51670171-A8EA-4213-BEE3-135B00FF846B}">
                            <Child0 Name="Return" Owner="{71D611E7-1C99-4A81-A196-DBB2A84E4D2C}" />
                            <Child1 Name="Sale" Owner="{A2F629A5-2880-4B9F-B2DD-EB8208BED5F1}" />
                        </Child2>
                        <Child3 Name="btn_Logout" Owner="{9C3F168B-C4E8-4258-9BB9-87CC9E039FBD}" />
                        <Child4 Name="btn_Process" Owner="{07DFBDF4-6C09-4139-B6AD-2C50B0923BC2}" />
                        <Child5 Name="menu_SubFunctionalities" Owner="{6CCA1F99-BA33-44F7-9862-40DDE3BA9754}">
                            <Child0 Name="Authorization" Owner="{FD0D731E-F3C7-449A-8ECE-708D04E678AA}" />
                            <Child1 Name="Credit_Return" Owner="{1602182C-8EE3-4850-9EE9-B85169EEB8C7}" />
                            <Child2 Name="Offline_Sale" Owner="{200BC451-D439-4917-8074-AE199A7F9E1F}" />
                            <Child3 Name="Offline_Authorization" Owner="{CD66638D-2DA2-475F-A7E8-A08F7AE699EB}" />
                            <Child4 Name="Tip_Adjustment" Owner="{75DEE507-E479-466F-8C1B-DEE53DBF9086}" />
                            <Child5 Name="MOTO_E_Commerce" Owner="{38EFF717-EFFD-42A9-97BE-08CC1DCB1241}" />
                            <Child6 Name="Check_Verify_Only" Owner="{CF9E9E51-7F60-4685-B261-4C6B952E92C6}" />
                            <Child7 Name="Check_One_Time_ACH" Owner="{19A30406-3B70-4439-8137-65ED56DA015B}" />
                            <Child8 Name="HMS_Redeem" Owner="{DDF674EB-4C86-4132-AA64-E207C8790585}" />
                            <Child9 Name="HMS_Load" Owner="{68C7E4CC-9401-4081-943A-CFBE832589BE}" />
                            <Child10 Name="HMS_Activate" Owner="{D5457A26-C6BD-4FFE-AA11-320AD8380790}" />
                            <Child11 Name="HMS_Reward" Owner="{363CB1F2-CEE8-4FD1-909D-AE38709817D9}" />
                            <Child12 Name="HMS_Transfer" Owner="{C38D7143-5B7F-410C-82C3-D5D5CAC96B8C}" />
                            <Child13 Name="HMS_Add_Alias" Owner="{B3FBD0B4-C998-432D-81BF-F351CCDBC72C}" />
                            <Child14 Name="HMS_Remove_Alias" Owner="{E8EA3B6E-FFBD-4924-A60F-DE6610A34581}" />
                            <Child15 Name="Prepaid_Add_Value" Owner="{4A880530-E28D-45A0-8326-21AD4DD12205}" />
                            <Child16 Name="Check_Sale" Owner="{8123F966-8AA1-478B-99FC-0D3C22128D90}" />
                            <Child17 Name="HMS_Balance_Inquiry" Owner="{9DEB16E5-44E7-4A5B-8F7F-23A4EBA60861}" />
                            <Child18 Name="EBT_Food_Stamp_Sale" Owner="{FE300955-B674-4331-B3DA-56087599AE27}" />
                            <Child19 Name="EBT_Food_Stamp_Voucher" Owner="{C292106D-CDD0-4363-AD1F-16F4EE7AD560}" />
                            <Child20 Name="EBT_Cash_Benefit_Sale" Owner="{EE4383E5-4D81-4524-92E2-A74AA7970A87}" />
                            <Child21 Name="EBT_Food_Stamp_Return" Owner="{AF37C57C-1B7A-4F6B-BF6E-2F9AF31C5FD3}" />
                            <Child22 Name="EBT_Food_Stamp_Balance_Inquiry" Owner="{BD25AA42-3944-4554-964F-CA551B85A365}" />
                            <Child23 Name="Account_Verify" Owner="{DEC3565E-B6F8-4E37-86CE-90C0FF3AC1A8}" />
                            <Child24 Name="dlg_Error" Owner="{69463272-1A26-46DC-B675-FA7550CBFBA9}">
                                <Child0 Name="YesButton" Owner="{29B84C6F-A0D5-49B6-B2EF-CA67C68517DB}" />
                                <Child1 Name="FR_Possible_fraud_detected_" Owner="{86C16C91-9689-46A9-A342-A0C08BB310AC}" />
                                <Child2 Name="NoButton" Owner="{9E406710-E2A0-4A79-A9D6-C14712B13E34}" />
                                <Child3 Name="Error" Owner="{15542A5E-D066-4D11-8108-AEE670D346DA}" />
                            </Child24>
                            <Child25 Name="Commercial_Card_Prompt" Owner="{19F433EF-8931-4EC7-8987-0E1FB0775257}">
                                <Child0 Name="Commercial_Card_Prompt" Owner="{B9262AB2-DA37-4288-B87D-F6DB03827573}" />
                                <Child1 Name="PO_Number" Owner="{CE44A904-8A3B-4F5D-A43D-BB01D37170C5}" />
                            </Child25>
                            <Child26 Name="ChildWindow" Owner="{7416B297-CEC8-42F2-8123-A2A1C2EE77FE}">
                                <Child0 Name="ResultsGrid" Owner="{26A9D1C1-8905-43D1-BC74-1F817E53A520}" />
                                <Child1 Name="OkButton" Owner="{CD3722E5-7B56-450B-A5DD-69C6B6682E85}" />
                                <Child2 Name="AddDocumentControl" Owner="{86D0C2C9-C7A9-440B-A8ED-F4AE9CBE2DA6}" />
                                <Child3 Name="txt_recipient" Owner="{DEBB303D-EB6F-4037-BC31-CDF5D7C4EA08}" />
                                <Child4 Name="RepeatSaleControl" Owner="{F371CC4B-8612-4224-A9BC-A4C97F5A5668}" />
                                <Child5 Name="TipAdjustmentControl" Owner="{F2762A53-5750-47DC-8E4C-91F2872EE840}" />
                                <Child6 Name="ReturnControl" Owner="{1B357D4D-065E-4F9F-B252-F2133D0B11A1}" />
                                <Child7 Name="AddToBatchControl" Owner="{F5B213B3-2FFB-4289-9A7A-FEF403A49980}" />
                                <Child8 Name="VoidControl" Owner="{BA064BC9-16D1-4D2F-849A-645E58CDDB21}" />
                                <Child9 Name="txt_Recipients" Owner="{EAD01CA6-B449-4F9F-ADE7-8A190E9C344C}" />
                            </Child26>
                            <Child27 Name="Declined" Owner="{B2FD13E5-4CBB-4FCF-8931-941A262B4345}">
                                <Child0 Name="YesButton" Owner="{29270C7D-5995-4F9A-81B3-253DBD6EDF60}" />
                            </Child27>
                            <Child28 Name="Void_Confirmation" Owner="{B3A26216-078B-4793-8DCE-38350466D986}">
                                <Child0 Name="YesButton" Owner="{040E96A0-2C8A-42BA-8BFA-ECDCD7506C35}" />
                            </Child28>
                            <Child29 Name="Batch_Close_Confirmation" Owner="{D82695FB-05BB-42A3-B7B6-81E1BC0A0EF6}" />
                            <Child30 Name="Notification" Owner="{4C650AD1-EEF8-463D-A26A-7B1FA13277B3}">
                                <Child0 Name="YesButton" Owner="{F2A1082A-DF29-403F-A6DD-09277D3C5534}" />
                                <Child1 Name="Notification" Owner="{DBABEF5C-81F6-40A9-9F68-E681B94D0BFB}" />
                            </Child30>
                            <Child31 Name="About" Owner="{100ECAE5-9B02-442B-AF77-B89A3A0AD4D4}">
                                <Child0 Name="RichTextBox" Owner="{E37236C8-741C-41B7-AAA7-27D48946D099}" />
                            </Child31>
                            <Child32 Name="Success" Owner="{CDEE64E2-DFA9-4E2D-AE40-3F3083B2CF56}">
                                <Child0 Name="YesButton" Owner="{E50525B2-F6AF-45B5-8CB5-53E84D964962}" />
                            </Child32>
                            <Child33 Name="Delete_Confirmation" Owner="{334139E2-5E2F-4C23-AA2F-C6AFD66E41FF}" />
                            <Child34 Name="Next_Bill_Date" Owner="{E5010D0F-895A-4168-A241-2B3FC0B73827}">
                                <Child0 Name="Change_due_date_for_all_future_transactions" Owner="{C2D3AC47-C113-4B2F-BEE5-CA66E8C67C0C}" />
                                <Child1 Name="One_time_change" Owner="{12A0C6B0-F53F-4139-A921-F155FD5DF334}" />
                                <Child2 Name="Continue" Owner="{60BF6041-D119-4FC7-915B-2912F5AA9DE7}" />
                            </Child34>
                            <Child35 Name="Sale_By_Tran_ID" Owner="{E014A1C1-A498-48CE-9E61-8B46DCEBFFE9}" />
                            <Child36 Name="Tip_Adjustment2" Owner="{29030CC3-A5BD-4669-8ACB-4C8A68EA0118}" />
                            <Child37 Name="Tip_Adjustment_Confirmation" Owner="{73F81679-4FCB-45DB-9959-68210A708B83}" />
                            <Child38 Name="Return_Prompt" Owner="{14F1D112-5B3F-4EA1-9726-5FFBDC5EB4AA}" />
                            <Child39 Name="Return_Confirmation" Owner="{00003714-4A58-4014-ADD4-4599D0C04ADB}" />
                            <Child40 Name="Impersonate" Owner="{C47364F8-76CD-4E14-ABAA-C8861ABDE868}">
                                <Child0 Name="Search" Owner="{6CA2360A-DDD5-4D96-9A14-3ED62D952E26}" />
                                <Child1 Name="Merchant_ID_" Owner="{26095961-AC3B-4524-9EAE-D5F1A543E2A3}" />
                                <Child2 Name="resultsDataGrid" Owner="{C5AFB58D-4C7C-4F61-8CE8-48DE094C15BD}" />
                                <Child3 Name="Devices_" Owner="{8E6995B4-F5E5-4ECC-B61C-3201DFD9AFB3}" />
                                <Child4 Name="ComboBox" Owner="{BD6F89FE-A5E6-44E5-B6BF-C4D8278E87B7}" />
                                <Child5 Name="searchParameterTextBox" Owner="{4A87BC39-741A-44FB-A776-2D14687F6EF1}" />
                                <Child6 Name="Impersonate_2" Owner="{72A37B7F-EA72-4B90-8B82-BA4DBB9CA06B}" />
                                <Child7 Name="Cancel" Owner="{61EA2455-9D5D-4DED-A077-1629A0B5AEC9}" />
                            </Child40>
                            <Child41 Name="BatchCloseConfirmation" Owner="{6FCA1EAD-EA31-47BA-A77B-0CCB7A2787E7}">
                                <Child0 Name="Yes" Owner="{84FC2583-0336-40F5-946C-3E3AED2C5B52}" />
                                <Child1 Name="No" Owner="{C9032129-E791-47AB-8AF9-EC12F3CF65DD}" />
                            </Child41>
                            <Child42 Name="Add_To_Batch" Owner="{B7D893B3-3747-41BC-AA54-47DC865711B6}">
                                <Child0 Name="OkButton" Owner="{9C9CD291-F232-4C62-B1A7-23339F341F52}" />
                                <Child1 Name="CancelButton" Owner="{A083769F-E3C4-43BD-914A-FAB642B9200C}" />
                            </Child42>
                            <Child43 Name="Tip_Adjustment_Transaction_not_in_Batch" Owner="{7BC2D6C7-487E-4092-A999-7F085357C08F}" />
                            <Child44 Name="Override_Confirmation" Owner="{FC7D7FD6-BD76-4CC0-858D-5EE34D80F77E}">
                                <Child0 Name="YesButton" Owner="{389E1CD1-80FD-408B-9ABB-9E6BA7D0245E}">
                                    <Child0 Name="Override" Owner="{43A4A7D8-11F8-4831-BCC7-DECFFCDAC21E}" />
                                </Child0>
                            </Child44>
                            <Child45 Name="Print_Preview_Historical_Batch" Owner="{8A2BE18A-60B1-4EBC-B06F-AAFE9ED274A5}">
                                <Child0 Name="CloseButton" Owner="{9B31A1EB-008D-46EC-915E-4D0E42F7C068}" />
                            </Child45>
                            <Child46 Name="Result" Owner="{98F69015-12BF-4858-912B-2A5E34D7087F}">
                                <Child0 Name="YesButton" Owner="{EED6049E-D167-41E1-BE25-D327627679C9}" />
                                <Child1 Name="Result" Owner="{3C74576E-5AA0-486B-9A6E-ED85D6212C3B}" />
                            </Child46>
                            <Child47 Name="Prompt" Owner="{A195F989-7F1D-49A6-B2E8-76FEB2B59A96}">
                                <Child0 Name="Prompt" Owner="{8B969EFF-51D3-474A-9372-ABBD02F15A1F}" />
                            </Child47>
                        </Child5>
                        <Child6 Name="txt_recipient" Owner="{AE6661B6-E810-4A84-803C-016C326465C7}" />
                        <Child7 Name="lbl_EmailProcessed" Owner="{9F0212F6-F729-4A1F-8EFC-B714E95A537F}" />
                        <Child8 Name="btn_EmailSent_OK" Owner="{FDE9A59F-F6C7-4887-B1F8-C45C4476531C}" />
                        <Child9 Name="FooterFrame" Owner="{580E3699-D7AD-4FA0-9AC6-6FFB4917367C}">
                            <Child0 Name="lbl_ApplicationVersion" Owner="{413156BD-8222-42E4-A444-692BD0576D57}" />
                        </Child9>
                        <Child10 Name="menu_MainFunctionalities" Owner="{C4098CD6-F0BB-44ED-AACD-20E1125AB2D1}">
                            <Child0 Name="Debit" Owner="{49553D88-5B4C-47F1-9B0E-CD312E16B29B}" />
                            <Child1 Name="HMS" Owner="{8B485103-E06C-4224-8A9B-03DB93A20C6E}" />
                            <Child2 Name="PrePaid" Owner="{2008F221-26A1-44D5-A64D-091C14823454}" />
                            <Child3 Name="EBT" Owner="{CDED5FF8-1F80-4AFE-94B3-C7E416A101C6}" />
                            <Child4 Name="Reporting" Owner="{5DF2D460-6A03-4D38-A73C-D6BA5CFABFF8}" />
                            <Child5 Name="Admin" Owner="{66080613-20FF-4B28-BDB9-058FCEF6D360}" />
                            <Child6 Name="Support" Owner="{3A858F34-FF5A-434A-847D-5FA448D30B7A}" />
                            <Child7 Name="lbl_Errors" Owner="{04353457-8412-497B-B084-623B0AD2E3A1}" />
                            <Child8 Name="ResultsDataGrid" Owner="{195F7694-204B-4F0E-AA2D-D2E98A2A21C6}">
                                <Child0 Name="RowsPresenter" Owner="{5CE39D67-776E-4225-B9B6-839B20DFE4BD}" />
                            </Child8>
                            <Child9 Name="PayPlan" Owner="{E0531421-0946-4F47-BB72-64667A56EF86}" />
                            <Child10 Name="Cancel_Impersonation" Owner="{02B95C87-7C92-4219-BF38-6FD5DA413445}" />
                            <Child11 Name="BreadcrumbFrame" Owner="{2CAFCECA-3C35-4C47-831A-2EF4E870096F}">
                                <Child0 Name="Failed_Schedules_Detail" Owner="{FC45C190-4EC9-4818-AABA-5656709CBD07}" />
                            </Child11>
                        </Child10>
                        <Child11 Name="lbl_Header" Owner="{26E6DD3F-D5E5-42CE-BAD2-139BCB024CE5}" />
                        <Child12 Name="GridContainer" Owner="{86E0BB19-3E03-4296-9B63-072F56ACCFAB}">
                            <Child0 Name="TipAmountTextBox" Owner="{10B394EA-9E71-4564-BAB5-801231FCB977}" />
                        </Child12>
                        <Child13 Name="dlg_Success" Owner="{7AB3A048-A37A-45DE-8375-FD37CAD432C5}" />
                        <Child14 Name="lbl_Errors" Owner="{6D47D531-C537-4D2B-98C7-FF9F2A0B78E4}" />
                        <Child15 Name="Close_Batch" Owner="{C138C485-42D5-4AEC-9FB5-25D03D9C6E61}" />
                        <Child16 Name="btn_Export" Owner="{8991805F-EC88-4F23-9027-28D7E7C89444}" />
                        <Child17 Name="popup_Export" Owner="{5DD87E3F-C854-4F2E-BE1B-20CE50D85467}">
                            <Child0 Name="XML" Owner="{501EB044-8779-4246-A94C-58DA989A3EC5}" />
                            <Child1 Name="PDF" Owner="{1612790B-F3AB-4510-9F38-5CDC10A29782}" />
                            <Child2 Name="CSV" Owner="{471B8428-5826-4BF0-BB74-2EE5FBCA4607}" />
                            <Child3 Name="Tab_Delimited" Owner="{E9EC5CBE-0AB0-44DD-9A0A-9B682CBAE2A3}" />
                            <Child4 Name="Excel" Owner="{0DA3F679-87E9-4565-89F5-8FA21E026F82}" />
                        </Child17>
                        <Child18 Name="InputScrollViewer" Owner="{A9D51C9E-E473-409F-BD1B-700A89C47C79}">
                            <Child0 Name="Grid1" Owner="{7D49E839-B8F4-478E-9C1A-615E59B53E8B}">
                                <Child0 Name="RowsPresenter" Owner="{27F356B6-37BA-4B6B-8313-9B1FCA30D299}">
                                    <Child0 Name="Payment_" Owner="{5887EEF4-E1E0-4182-927B-03DB1430F3B8}">
                                        <Child0 Name="DataGridCell" Owner="{34DFAFF3-7A1B-4655-8B98-FCC2D12080EB}">
                                            <Child0 Name="TextBox" Owner="{1A30F689-71FE-4670-83F5-6D9BD5A6C157}" />
                                            <Child1 Name="Charge" Owner="{7D9B2BE5-5B68-4BF2-87EC-1820B7530B76}" />
                                        </Child0>
                                        <Child1 Name="DataGridCell2" Owner="{4D6D5BD8-D857-4C88-B053-462C85711289}">
                                            <Child0 Name="Button" Owner="{BF7A1BFE-AB51-41A1-A633-47952269DF54}">
                                                <Child0 Name="EditImage" Owner="{CA4A6F58-61E3-407A-B4E0-40AB444AE279}" />
                                            </Child0>
                                            <Child1 Name="Button2" Owner="{7D493838-CDF6-4AD3-AC3D-6AEE07FBF9CB}" />
                                        </Child1>
                                        <Child2 Name="DataGridCell3" Owner="{7826B845-040D-4EC8-9B22-722F9D19DBFB}">
                                            <Child0 Name="Charge_Now" Owner="{A1330906-6F2C-4D0C-9EBB-BFE937740312}" />
                                        </Child2>
                                    </Child0>
                                </Child0>
                            </Child0>
                            <Child1 Name="Grid2" Owner="{0391870C-1EC1-4A15-9DD5-F597164D6849}">
                                <Child0 Name="RowsPresenter" Owner="{6CF7191D-AEF3-45D8-A7B2-9CC2917307C6}">
                                    <Child0 Name="Schedule_" Owner="{CF01792B-0EEA-4D6D-ADDF-E05B6A1DA99C}">
                                        <Child0 Name="DataGridCell" Owner="{699998EB-EAD8-4FEF-9FCC-01D68D9FFF4B}">
                                            <Child0 Name="Button" Owner="{99CFBA63-858B-4BDA-BDD9-187CFDC2B00E}" />
                                            <Child1 Name="Button2" Owner="{2DA4596E-18CA-45E5-B1F4-287E13523B68}" />
                                        </Child0>
                                    </Child0>
                                </Child0>
                            </Child1>
                            <Child2 Name="st_and_15th_day_of_each_month" Owner="{E3DE947C-D452-4A13-B15C-587C34599105}">
                                <Child0 Name="st_and_15th_day_of_each_month" Owner="{2FDC93B2-302E-49C1-BD6F-E81944138BD2}" />
                            </Child2>
                            <Child3 Name="th_and_last_day_of_each_month" Owner="{70594E6C-70B4-4F03-815E-FB56C5946549}">
                                <Child0 Name="th_and_last_day_of_each_month" Owner="{B6ECEF22-3275-427B-BE02-8F04E7FA0075}" />
                            </Child3>
                            <Child4 Name="Search" Owner="{B7E6B80E-098F-40AE-B578-807C355D4DD2}" />
                            <Child5 Name="Close_Batch" Owner="{9C232C49-5779-4316-A401-AD16202F9E3D}" />
                            <Child6 Name="ResultsDataGrid" Owner="{9D1A681F-734D-4288-A4BA-B2910195568D}">
                                <Child0 Name="RowsPresenter" Owner="{9844CD57-8701-466C-A36A-506B22C91021}" />
                                <Child1 Name="ColumnHeadersPresenter" Owner="{6482B3A6-5F72-40EC-9690-336BA8FDADE3}" />
                            </Child6>
                            <Child7 Name="VerticalScrollBar" Owner="{0C9FF91F-6C7E-41D6-8D62-B8EB34D5152D}" />
                            <Child8 Name="ResultsDataGrid2" Owner="{87BB63BA-84A5-4EAB-9C33-D8118D285006}" />
                            <Child9 Name="Edit_Customer" Owner="{6F4F6960-2A37-4C6A-B101-7D0DA12CA08B}" />
                            <Child10 Name="Charge_Now" Owner="{62863E18-E0CA-4B78-BD36-518F68FDF280}" />
                            <Child11 Name="Add_New_Payment_Method" Owner="{76D8B76A-286D-4BF1-8C7C-5071CF7131F3}" />
                            <Child12 Name="Add_Payment_Method" Owner="{7CBFE201-0B17-485E-874E-66557D161F6F}" />
                            <Child13 Name="Add_Schedule" Owner="{AD5A8F31-0BB4-45DB-9AF5-DB2A9E9EE856}" />
                            <Child14 Name="Update" Owner="{934FF193-8D0D-4ED2-A19A-5EFC75E77594}" />
                            <Child15 Name="No_Records" Owner="{9B5F9762-6565-4501-93B4-E604852B9C14}" />
                            <Child16 Name="SummaryListBox" Owner="{EE9937D1-19CD-4368-A3F1-D5F584C48443}" />
                            <Child17 Name="errorsMessage" Owner="{CFDFAE1C-9D0B-43EB-A476-678ACF5C2BB7}" />
                        </Child18>
                    </Child1>
                    <Child2 Name="page_PorticoFunctionalilties" Owner="{001B2F54-E626-409C-8A8F-A54F57C49883}">
                        <Child0 Name="menu_MainFunctionalities" Owner="{E5E32C4B-D1D1-4271-970E-D421A3A4435C}">
                            <Child0 Name="ContentFrame" Owner="{78341657-9CBF-482F-A26A-5EA62C21270A}">
                                <Child0 Name="GridContainer" Owner="{59593BE3-08CD-42C3-9551-7CCB8E75A4EA}">
                                    <Child0 Name="Credit_Card_Details" Owner="{661DFF05-EC2F-4ACD-9660-747A00A91A1A}" />
                                </Child0>
                                <Child1 Name="AM" Owner="{EF88623A-CC5A-4292-BA24-9D793A31380A}">
                                    <Child0 Name="StartDateDatePicker" Owner="{354E5284-EDAE-4D7C-9029-18EA8C70B521}" />
                                </Child1>
                                <Child2 Name="Search" Owner="{A8B3BD0B-D501-4B8F-A999-052372591003}" />
                            </Child0>
                            <Child1 Name="Credit" Owner="{4DEACF7C-B8BE-45D5-AC58-1277A8046FAC}" />
                            <Child2 Name="Debit" Owner="{4AC66505-123D-468E-BB26-A49490FABFD7}" />
                            <Child3 Name="Check" Owner="{B3E19A37-7E51-4379-998F-77D5ACF15624}" />
                            <Child4 Name="HMS" Owner="{412CC1DE-3AEF-4111-A8B6-D2CC1CFB1181}" />
                            <Child5 Name="PrePaid" Owner="{AF690C58-B55D-4E3C-8DF5-33E2C446C4BA}" />
                            <Child6 Name="EBT" Owner="{6049FE2E-0F45-4E1A-B6EB-EC97E90CB88A}" />
                            <Child7 Name="Reporting" Owner="{E4A26052-EC04-42B2-A1F7-664EF4A7645D}" />
                            <Child8 Name="Admin" Owner="{0B804D68-BAC8-426A-BCA9-E7786CDEB031}" />
                            <Child9 Name="Support" Owner="{52F2F374-1684-4290-B3D9-691EBDCD0D37}" />
                            <Child10 Name="HeaderFrame" Owner="{AD49DD7F-7138-484B-A85E-61B19A0BAF1C}">
                                <Child0 Name="btn_Apply" Owner="{DD997C8E-5D89-4683-A125-E9A3B54CFF94}" />
                            </Child10>
                            <Child11 Name="txt_LoginUserName" Owner="{899FA620-64EF-4849-A388-A7C4DF61CB38}" />
                            <Child12 Name="txt_LoginPassword" Owner="{26D78B49-71E2-4F2A-8453-1769B67DB64B}" />
                            <Child13 Name="btn_Login" Owner="{4F9B29B7-0ACA-466A-89FF-6C8A0AC57724}" />
                        </Child0>
                        <Child1 Name="menu_Credit" Owner="{EF9A7C69-43E6-47DF-88E8-67A6849D928D}" />
                        <Child2 Name="page_Results" Owner="{AFDEAE52-E9D4-441B-A04F-FE15C6815BBF}">
                            <Child0 Name="btn_EmailControl" Owner="{6BAC9947-FDF2-4F04-8A32-D89B02FBB46F}" />
                            <Child1 Name="btn_PrintControl" Owner="{293B9ECA-00E5-49E2-9387-79F6F23918F2}" />
                            <Child2 Name="grd_Results" Owner="{1B08B2BA-9A20-421F-9A1B-D16C57679857}">
                                <Child0 Name="RowsPresenter" Owner="{EE6BAE45-E4FA-4BFB-9069-6BCD2EFCAFAE}">
                                    <Child0 Name="Hps_VT_UI_Presentation_Controls_TransactionResultItem" Owner="{9DCB2E6B-BC9E-4985-A439-924C02B85062}">
                                        <Child0 Name="DataGridCell" Owner="{9E1FC0FF-5B75-4CE3-8DC3-FF148F05DD0B}">
                                            <Child0 Name="TextBlock" Owner="{CC1F8906-FC56-409D-B9A0-A922A8E111F6}" />
                                        </Child0>
                                        <Child1 Name="DataGridCell2" Owner="{F088DF96-3E71-450C-95AF-7FD1F4EFB638}">
                                            <Child0 Name="TextBlock" Owner="{5BE59093-814B-4AB1-929F-2287F8A7B0B8}" />
                                        </Child1>
                                    </Child0>
                                    <Child1 Name="Hps_VT_UI_Presentation_Controls_TransactionResultItem_2" Owner="{FD344257-DA1B-46C3-9229-3B0516C2FB4B}">
                                        <Child0 Name="DataGridCell" Owner="{DEF9EA62-3D10-4B12-8E7C-517D6E0409F3}" />
                                        <Child1 Name="DataGridCell2" Owner="{7CBBBB7B-FA3B-4E43-A655-BC4BF3DBF99D}" />
                                    </Child1>
                                    <Child2 Name="Hps_VT_UI_Presentation_Controls_TransactionResultItem_16" Owner="{615169A2-09BE-477D-A275-8D95921A09DD}">
                                        <Child0 Name="DataGridCell" Owner="{EFBF5725-72B0-4115-AFCC-75A939BEFCD4}" />
                                    </Child2>
                                </Child0>
                            </Child2>
                            <Child3 Name="txt_Recipient" Owner="{68C2111F-3F5E-4FA5-B658-B1504C9C73CA}" />
                            <Child4 Name="btn_SendEmail" Owner="{81F48E23-BC0A-4D4D-A781-D94148E6FDD4}" />
                            <Child5 Name="btn_OK" Owner="{21E755EA-8C6C-4449-A4C7-4A16C525E64A}" />
                            <Child6 Name="btn_AddAttachment" Owner="{01E97D5D-BF33-42B6-8CB6-22881DA1585B}" />
                            <Child7 Name="VoidControl" Owner="{031BB042-1089-4587-94C7-9451FA22F95C}" />
                            <Child8 Name="OK" Owner="{AD2449ED-5640-4AF9-8C4E-E6B22BE34E06}" />
                            <Child9 Name="TipAdjustmentControl" Owner="{1AF35C78-CA99-43F6-A8A0-8AB04E1C1B85}" />
                        </Child2>
                        <Child3 Name="Debit_Return" Owner="{13F9ECA1-3C4E-4BEF-997C-FA6021245CD9}" />
                        <Child4 Name="Error" Owner="{53183FBF-7020-4B86-BD34-3C0C8FE85B5A}">
                            <Child0 Name="Error" Owner="{6B5971B5-EA9B-48ED-8B3D-25F47C4D63FE}" />
                            <Child1 Name="YesButton" Owner="{576292E6-7D9A-4E69-8851-E62611D4F24E}" />
                        </Child4>
                        <Child5 Name="menu_SubFunctionalities" Owner="{161A0723-97E9-49B5-B2CD-47B01C543372}">
                            <Child0 Name="ChildWindow" Owner="{AFDEAE52-E9D4-441B-A04F-FE15C6815BBF}">
                                <Child0 Name="ResultsGrid" Owner="{1B08B2BA-9A20-421F-9A1B-D16C57679857}" />
                                <Child1 Name="Approved" Owner="{A29737C2-9683-4FCF-BEAB-76243EAD8293}" />
                                <Child2 Name="EmailControl" Owner="{6BAC9947-FDF2-4F04-8A32-D89B02FBB46F}" />
                                <Child3 Name="PrintControl" Owner="{293B9ECA-00E5-49E2-9387-79F6F23918F2}" />
                                <Child4 Name="Recipient" Owner="{68C2111F-3F5E-4FA5-B658-B1504C9C73CA}" />
                                <Child5 Name="SendEmail" Owner="{81F48E23-BC0A-4D4D-A781-D94148E6FDD4}" />
                                <Child6 Name="OkButton" Owner="{21E755EA-8C6C-4449-A4C7-4A16C525E64A}" />
                                <Child7 Name="ZIP_Code" Owner="{2C8BBAC6-BC3C-4E5B-B44E-7DB051DF5EAC}" />
                                <Child8 Name="Name" Owner="{8B93E482-2835-4CF1-AF0C-528502855F7C}" />
                                <Child9 Name="Transaction_Type" Owner="{D0CAB55E-9204-458E-8A5F-C791DD110FC8}" />
                                <Child10 Name="Customer_Copy" Owner="{B812140A-8FED-48B6-A596-B4CA9FAF5E63}" />
                                <Child11 Name="Date_" Owner="{C640653F-72FE-44F6-A20D-D01E5F45FC54}" />
                                <Child12 Name="ClosePreview" Owner="{6A3F8191-444B-4480-9FD0-C5579DA644A8}">
                                    <Child0 Name="Cancel" Owner="{A769E97B-E023-4664-A5AF-564FCD0DB225}" />
                                </Child12>
                                <Child13 Name="www_google_com" Owner="{9B08CD3B-3C86-4354-9B21-61E681A617D2}" />
                            </Child0>
                            <Child1 Name="MOTO_E_Commerce" Owner="{E9698F3C-FC8F-4094-B50E-77538B01CC67}" />
                            <Child2 Name="Balance_Inquiry" Owner="{6658094F-672E-4165-8162-5C41B76291EE}" />
                            <Child3 Name="Sale" Owner="{656D793F-4A90-450A-B4A0-879CB6D42058}" />
                            <Child4 Name="Error" Owner="{53183FBF-7020-4B86-BD34-3C0C8FE85B5A}" />
                            <Child5 Name="Commercial_Card_Prompt" Owner="{C7961684-E09F-40C2-B41F-C99EF35F65AC}">
                                <Child0 Name="CpcPoNumberTextBox" Owner="{47892ACC-8A71-4CEB-9A91-E29F6A97FBB0}">
                                    <Child0 Name="ContentElement" Owner="{F947DECF-DBA5-43AE-9471-80B62632998D}" />
                                </Child0>
                                <Child1 Name="CpcTaxAmountTextBox" Owner="{A0222A1B-5AE6-4EA5-BA29-20AF7C302F59}" />
                                <Child2 Name="CpcTaxExemptCheckBox" Owner="{B1B104E2-7710-4DE7-85E0-9FD0C671C1EA}" />
                                <Child3 Name="CpcProcessButton" Owner="{11FF064A-E1E8-498E-A924-8B0DA3FF10CF}">
                                    <Child0 Name="Process" Owner="{9A0A2394-E85B-4692-ABDC-27742A6F8B38}" />
                                </Child3>
                            </Child5>
                            <Child6 Name="Credit_Return" Owner="{CCCA5F97-A4BF-4F76-8F08-981701BABC90}" />
                            <Child7 Name="dlg_Declined" Owner="{C457D077-F6BB-4384-AF18-06B6B2006D21}" />
                            <Child8 Name="dlg_Success" Owner="{54229E09-FAB7-41F3-A42A-13BF26C017BA}" />
                            <Child9 Name="Tip_Adjustment" Owner="{885BD5B9-282C-4729-94C6-7DA001B83375}" />
                            <Child10 Name="About" Owner="{FA73E9CE-1215-42A9-9DCD-E1CCA5FE4AFD}" />
                            <Child11 Name="Notification" Owner="{90F5F1BE-1FA4-4BBC-862F-C5A2FC22CB5B}">
                                <Child0 Name="YesButton" Owner="{9BABE2F4-7F29-496D-BC5D-4C66EED5D607}">
                                    <Child0 Name="OK" Owner="{9B95054D-5C65-4991-BD7C-3EEB498E51FD}" />
                                </Child0>
                            </Child11>
                            <Child12 Name="AMEX_Advance_Notice" Owner="{2D22F6A1-8846-4850-89C4-2FCB2009D088}">
                                <Child0 Name="Continue" Owner="{83705DE4-B841-4B60-9C6B-56D1479C1970}" />
                            </Child12>
                            <Child13 Name="Email_not_on_File" Owner="{E2D4092C-5AB1-44EB-A8B9-3688423E4077}" />                             
                        </Child5>
                        <Child6 Name="InputScrollViewer" Owner="{681A6371-7BCE-417E-9E34-59949AB64F0B}">
                            <Child0 Name="Edit_Customer" Owner="{BC1F4586-0C1E-4FD3-A05D-B64A99EC1943}" />
                            <Child1 Name="Update" Owner="{25131BBC-93B8-4F6C-B098-CCADAF5BDC32}" />
                            <Child2 Name="Grid2" Owner="{52541876-6A87-41F3-B94C-19D25137421E}">
                                <Child0 Name="RowsPresenter" Owner="{8F96569C-4DE4-46EE-95C6-66E93AD48288}">
                                    <Child0 Name="Schedule_" Owner="{AA5E2F62-73B2-433D-BB41-BC718C667476}">
                                        <Child0 Name="DataGridCell" Owner="{0FD2FE71-92A8-4DA4-8FED-9547EC35A95C}">
                                            <Child0 Name="Button" Owner="{8A00D074-8A02-4EFB-A14F-5489D016A1BD}">
                                                <Child0 Name="EditImage" Owner="{2251D415-40AD-4A93-96C7-113CBC71A500}" />
                                            </Child0>
                                        </Child0>
                                    </Child0>
                                </Child0>
                            </Child2>
                            <Child3 Name="ResultsDataGrid" Owner="{7EDA56F5-49CC-42C7-935E-F7EF7552DAE8}">
                                <Child0 Name="RowsPresenter" Owner="{BCD45A30-3F69-4BB8-9233-DFD5D241A747}" />
                            </Child3>
                            <Child4 Name="Add_Payment_Method" Owner="{B675B510-9A6B-4C41-9B53-408D45F1A9D1}" />
                            <Child5 Name="Add_Schedule" Owner="{95C57751-C5E0-4A59-981B-7043026BD617}" />
                            <Child6 Name="Add_New_Payment_Method" Owner="{45A056DF-99DF-40B6-8DBF-D6ECCBC4754F}" />
                            <Child7 Name="Delete" Owner="{B8D58D44-438F-4F48-A48B-E9BB1C795D20}" />
                            <Child8 Name="VerticalScrollBar" Owner="{5E299DD0-7057-4C2B-AA9D-61B803361F07}" />
                            <Child9 Name="Page_1_of_2" Owner="{E4C921A6-4D91-4F09-B85C-C7BB659CD183}" />
                            <Child10 Name="Cancel" Owner="{1BD6B4F6-228D-4620-A0A2-8606302A81C5}" />
                        </Child6>
                    </Child2>
                </Child0>
            </Child0>
            <Child1 Name="dlg_Open" Owner="{D2829184-6A42-48D4-ADF2-10A416C40146}">
                <Child0 Name="cmb_File" Owner="{2DCC40E5-86FB-46B3-B8A4-16E15ACD854E}">
                    <Child0 Name="cmb_FileName" Owner="{551C1C3E-81B1-4B51-B86E-9A82317CF4B1}">
                        <Child0 Name="txt_FileName" Owner="{ED3459CD-F98C-46E4-ABC3-C834E38522E7}" />
                    </Child0>
                </Child0>
                <Child1 Name="btn_Open" Owner="{05CC7DCA-80FB-40F4-A427-3FE0756F9E4D}" />
            </Child1>
        </Child2>
    </LogicalNodes>
</Root> 

应该在子级别解析此xml,并且应使用vba将其值写入excel。 (要么) 如何使用vba从每个父节点读取子节点并将它们写入excel。 有人可以帮忙吗

Expected ouput

1 个答案:

答案 0 :(得分:1)

XML无效,因为在 LogicalNodes 标记打开后,有一个打开的 Child 标记缺失。

在下面的代码中,我假设XML以这样的方式启动,第4行的缺少节点:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Root Signature="{5DCBAC3B-D39C-497C-9BE8-744CBADD37AA}" NameVersion="4" Cookie="3447">
    <LogicalNodes Name="Aliases" Owner="{BE401E45-B2D6-4FBA-931A-C2117D5C51AD}">
        <Child0 Name="missing" Owner="{449D4FD4-389C-4BEE-BCC2-8A6EC8BC73AB}">

一旦解决了这个问题,以下是一些在Excel中加载和显示节点的方法。

首先包括能够解析XML的引用:

  • 打开您的VBA应用程序编辑器
  • 从菜单中选择工具&gt;参考
  • 滚动列表并从列表中勾选 Microsoft XML,v6.0 ;
  • 可以关闭。

1。显示名称属性值,其父级右侧的子项

Function DisplayXmlTree(xmlNode As MSXML2.IXMLDOMNode, attrName As String, _
                        target As Range, Optional depth As Integer = 0) As Boolean
    Dim xmlChildNode  As MSXML2.IXMLDOMNode
    Dim xmlAttr       As MSXML2.IXMLDOMAttribute
    Dim col           As Integer
    Dim newRow        As Boolean

    For Each xmlChildNode In xmlNode.ChildNodes
        Set xmlAttr = xmlChildNode.Attributes.getNamedItem(attrName)
        If Not xmlAttr Is Nothing Then ' Nodes without name are ignored
            If newRow Then
                ' Repeat values from previous row
                For col = 0 To depth - 1
                    target.Offset(0, col) = target.Offset(-1, col)
                Next
            End If
            target.Offset(0, depth) = xmlAttr.Text
            If Not DisplayXmlTree(xmlChildNode, attrName, target, depth + 1) Then
                Set target = target.Offset(1)
            End If
            newRow = True
        End If
    Next
    DisplayXmlTree = xmlNode.ChildNodes.Length > 0
End Function

Sub LoadXML(filename As String, attrName As String, target As Range)
    Dim xmlDoc As New MSXML2.DOMDocument60

    If Dir(filename) = "" Then
        MsgBox "Could not find file " & filename
    ElseIf Not xmlDoc.Load(filename) Then
        MsgBox "Could not parse file " & filename
    Else
        DisplayXmlTree xmlDoc.DocumentElement, attrName, target
        MsgBox "Successfully loaded " & filename
    End If
End Sub

上面的代码使用递归来遍历XML树。以下是调用它的方法,指定要加载的文件,要显示的属性的名称以及要显示的目标单元格。

Sub Main()
    LoadXML "C:\Users\myself\Desktop\input.xml", "Name", Range("A2")
End Sub

输出将如下:

enter image description here

2。显示列中的所有属性值,行中的节点

在您指定输出格式之前,这是我的第一个答案:

Sub LoadXML(filename As String, target As Range)
    Dim xmlDoc   As New MSXML2.DOMDocument60
    Dim xmlNode  As MSXML2.IXMLDOMNode
    Dim xmlAttr  As MSXML2.IXMLDOMAttribute
    Dim rows     As Integer
    Dim cols     As Integer

    If Dir(filename) = "" Then
        MsgBox "Could not find file " & filename
    ElseIf Not xmlDoc.Load(filename) Then
        MsgBox "Could not parse file " & filename
    Else
        For Each xmlNode In xmlDoc.getElementsByTagName("*")
            If InStr(xmlNode.nodeName, "Child") = 1 Then
                cols = 0
                For Each xmlAttr In xmlNode.Attributes
                    target.Offset(rows, cols) = xmlAttr.Text
                    cols = cols + 1
                Next
                rows = rows + 1
            End If
        Next
        MsgBox "Successfully loaded " & filename
    End If
End Sub

调用此函数时,您可以传递XML文件名的完整路径,以及开始输出内容的单元格。

所以电话看起来像这样:

Sub Main()
    LoadXML "C:\Users\myself\Desktop\input.xml", Range("A1")
End Sub

输出将如下:

enter image description here