Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将多个XML中的值提取到excel中?_Xml_Excel_Vba - Fatal编程技术网

如何将多个XML中的值提取到excel中?

如何将多个XML中的值提取到excel中?,xml,excel,vba,Xml,Excel,Vba,我有大量的XML都是这种形式的(有些有不同数量的字段,但都包含我想要的某些信息) 不想要 不想要 希望 希望 不想要 不想要 希望 希望 不想要 不想要 不想要 不想要 不想要 不想要 我想要一个excel表格,列标题为“名称”、“子字段3”、“givenName”、“familyName”(从上面开始),每一行都有来自每个XML的这些值。我是一个编程初学者,所以我不知道如何编程。只从单个xml中提取我想要的值,然后2.编写一些代码来执行1。对于文件夹中的每个XML文件。有人能帮我吗 编辑:

我有大量的XML都是这种形式的(有些有不同数量的字段,但都包含我想要的某些信息)


不想要
不想要
希望
希望
不想要
不想要
希望
希望
不想要
不想要
不想要
不想要
不想要
不想要
我想要一个excel表格,列标题为“名称”、“子字段3”、“givenName”、“familyName”(从上面开始),每一行都有来自每个XML的这些值。我是一个编程初学者,所以我不知道如何编程。只从单个xml中提取我想要的值,然后2.编写一些代码来执行1。对于文件夹中的每个XML文件。有人能帮我吗

编辑:

实际xml示例

 <?xml version="1.0" encoding="UTF-8"?> <message submitted="y" xmlns="u">
 <s><m>4</m><me>0</me>
 <oc>I</oc>
 <os>E</os><dr>21</dr>
 <tr>1</tr><dc>20/dc>
 <tc>1</tc><ds>2</ds>
 <ts>1</ts></sh><formData><c><identifier edgeitem="ZCO01b">
 <type edgeitem="ZCO01b">C</type><value edgeitem="ZCO01b">172</value>
 </identifier><name edgeitem="ZCO01a">JMTGN</name></c>
 <pb><ch><of><ef edgeitem="ZRP04b">20</ef><ad edgeitem="ZRG03c">
 <adL edgeitem="ZRP04d">2MR1</adL>
 <co edgeitem="ZRP04d">A</co><ov>true</ov>
 </ad></of></ch></pb><of><ch edgeitem="ZSD06a">
 <of><pe><ne edgeitem="ZSD06c"><gi edgeitem="ZSD06c">k</gi>
 <fa edgeitem="ZSD06c">o</fa>
 </ne><bi edgeitem="ZSD06d"><da edgeitem="ZSD06d">196</da>
 <ci edgeitem="ZSD06d">MNE</ci><st edgeitem="ZSD06d">VC</st>
 <co edgeitem="ZSD06d">Aua</co></bi>
 </pe><ad edgeitem="ZSD06h"><ad edgeitem="ZSD06h">24IC86</adL><co edgeitem="ZSD06h">uia</co><ov edgeitem="ZSD06i">true</ov><not><daC edgeitem="ZSD06b">29</daC>
 </not></ad></of><of><pe><name edgeitem="ZSD06c"><gs edgeitem="ZSD06c">jane</gs>
 <fae edgeitem="ZSD06c">ci</fae></name><bi edgeitem="ZSD06d"><da edgeitem="ZSD06d">198</da><ci edgeitem="ZSD06d">MLB</ci><st edgeitem="ZSD06d">VC</st>
 <co edgeitem="ZSD06d">Aul</co></bi></pe><ad edgeitem="ZSD06h"><adL edgeitem="ZSD06h">24IC</adL><co edgeitem="ZSD06h">uia</co><ov edgeitem="ZSD06i">true</ov>
 <not><daC edgeitem="ZSD06b">209</daC>
 </not></ad></of></ch></of><si><name edgeitem="ZDC00a"><givenNames edgeitem="ZDC00a">John </givenNames>
 <familyName edgeitem="ZDC00a">Citizen</familyName></name><ca edgeitem="ZDC00b">DI</ca><daS edgeitem="ZDC00c">200</daS><dec edgeitem="ZDC00d">true</dec></si></formData>
 <mes><asi><ebu><re>746</re>
 </ebu><asc><doc>181</doc></asc></asi>
 <cus><edg><re><type>RE</type>
 <qu>42</qu></re><ac>A08</ac>
 <tra>60</tra>
 <seq>1</se><tr>7046</tr>
 <mailbox>PR</mailbox><mode>PROCESS</mode></edge></customer></messageIdentifier>
 <asc><lo><ag>442</ag></loy></asc>
 <asco><re><dod>
 <dete>true</dete><fe>
 <lod>258</lod><lod>213</lod>
 <tot>0.00</tot></fe></dod></re>
 <prs><m>PRS</m><wa>false</wa><deb>false</deb>
 <maid>DP2</maid>
 <re>false</re></pro></asco>
 <wo><aga><ag>2</ag><agn>ATD</agn><co>LNY</co><pos>
 <adL>PO60</adL><adL>C3145</adL><co>AUA</co><asd>15055</asd>
 </pos><pe><te><nr>077</nr>
 </te></ph><fx><te><nr>057</nr>
 </te></fx></aga></wa></message>

40
我
E21
120/dc>
12
1.
C172
JMTGN
20
2MR1
阿特鲁
K
o
196
MNEVC
Aua
24IC86uiatrue29
简
ci198MLBVC
奥里奎亚图
209
约翰
公民身份
746
181
重新
42A08
60
17046
过程
442
真的
258213
0
错误
DP2
假的
2ATDLNY
PO60C3145AUA15055
077
057

此子节点迭代文件夹中的所有文件,如果找到任何XML,则调用第二个子节点


选项显式
'在Microsoft脚本运行时的代码编辑器中:工具>引用>复选框
公共子进程xmls()

Const FOLDER_NAME As String=“C:\Tmp”'搜索文件的代码在哪里?我将“C:\Tmp\file.xml”替换为我的xml所在的位置,但它只在A2中打印此位置,并且B2-E2字段为空。我更新了答案,以向您展示如何在文件夹中搜索所有文件,这将成功地遍历文件夹中的所有文件,但仍仅打印A列中的文件名,而B列和E列的标题正确,B2:E4仍为空。你知道可能是什么问题吗?我编辑了原始帖子,以包含一个实际xml文件的示例,其中我想要的值是“172”、“jmtgn”、“john”和“doe”。包含一个实际的xml非常有帮助——我知道问题所在,我正在解决它。快速提问:所有文件中相应字段(例如
)的边缘项代码是否相同我需要知道我是否可以依靠同一个字符串来识别所有文件中的每个字段。文件夹中的一些文件没有“边缘项”,而只有。。。还有。。。。然而,对于那些在标签中有边缘项的标签,Z。。。代码相同,因此对于标记中包含边缘项的所有文件,它将始终为。。对于其他两个字段,依此类推。
 <?xml version="1.0" encoding="UTF-8"?> <message submitted="y" xmlns="u">
 <s><m>4</m><me>0</me>
 <oc>I</oc>
 <os>E</os><dr>21</dr>
 <tr>1</tr><dc>20/dc>
 <tc>1</tc><ds>2</ds>
 <ts>1</ts></sh><formData><c><identifier edgeitem="ZCO01b">
 <type edgeitem="ZCO01b">C</type><value edgeitem="ZCO01b">172</value>
 </identifier><name edgeitem="ZCO01a">JMTGN</name></c>
 <pb><ch><of><ef edgeitem="ZRP04b">20</ef><ad edgeitem="ZRG03c">
 <adL edgeitem="ZRP04d">2MR1</adL>
 <co edgeitem="ZRP04d">A</co><ov>true</ov>
 </ad></of></ch></pb><of><ch edgeitem="ZSD06a">
 <of><pe><ne edgeitem="ZSD06c"><gi edgeitem="ZSD06c">k</gi>
 <fa edgeitem="ZSD06c">o</fa>
 </ne><bi edgeitem="ZSD06d"><da edgeitem="ZSD06d">196</da>
 <ci edgeitem="ZSD06d">MNE</ci><st edgeitem="ZSD06d">VC</st>
 <co edgeitem="ZSD06d">Aua</co></bi>
 </pe><ad edgeitem="ZSD06h"><ad edgeitem="ZSD06h">24IC86</adL><co edgeitem="ZSD06h">uia</co><ov edgeitem="ZSD06i">true</ov><not><daC edgeitem="ZSD06b">29</daC>
 </not></ad></of><of><pe><name edgeitem="ZSD06c"><gs edgeitem="ZSD06c">jane</gs>
 <fae edgeitem="ZSD06c">ci</fae></name><bi edgeitem="ZSD06d"><da edgeitem="ZSD06d">198</da><ci edgeitem="ZSD06d">MLB</ci><st edgeitem="ZSD06d">VC</st>
 <co edgeitem="ZSD06d">Aul</co></bi></pe><ad edgeitem="ZSD06h"><adL edgeitem="ZSD06h">24IC</adL><co edgeitem="ZSD06h">uia</co><ov edgeitem="ZSD06i">true</ov>
 <not><daC edgeitem="ZSD06b">209</daC>
 </not></ad></of></ch></of><si><name edgeitem="ZDC00a"><givenNames edgeitem="ZDC00a">John </givenNames>
 <familyName edgeitem="ZDC00a">Citizen</familyName></name><ca edgeitem="ZDC00b">DI</ca><daS edgeitem="ZDC00c">200</daS><dec edgeitem="ZDC00d">true</dec></si></formData>
 <mes><asi><ebu><re>746</re>
 </ebu><asc><doc>181</doc></asc></asi>
 <cus><edg><re><type>RE</type>
 <qu>42</qu></re><ac>A08</ac>
 <tra>60</tra>
 <seq>1</se><tr>7046</tr>
 <mailbox>PR</mailbox><mode>PROCESS</mode></edge></customer></messageIdentifier>
 <asc><lo><ag>442</ag></loy></asc>
 <asco><re><dod>
 <dete>true</dete><fe>
 <lod>258</lod><lod>213</lod>
 <tot>0.00</tot></fe></dod></re>
 <prs><m>PRS</m><wa>false</wa><deb>false</deb>
 <maid>DP2</maid>
 <re>false</re></pro></asco>
 <wo><aga><ag>2</ag><agn>ATD</agn><co>LNY</co><pos>
 <adL>PO60</adL><adL>C3145</adL><co>AUA</co><asd>15055</asd>
 </pos><pe><te><nr>077</nr>
 </te></ph><fx><te><nr>057</nr>
 </te></fx></aga></wa></message>