使用MS Excel VBscript从XML读取特定数据

时间:2014-07-08 10:50:11

标签: xml vba parsing

我是VB编程的新手,我正试图在解决方案工作中提到

我有一个以1分钟的速度刷新的网站,数据可以作为XML页面访问,我正在尝试加载XML文件并解析以读取特定行和特定列并更新到工作表(仅数值) XML文件中的时间戳随时间和结构而变化,标记,常量保持一致)。

要求是从每一行读取数据"行refno =" XX""和第1列,第5列 我的要求是非常频繁地读取数据,从而寻找专家建议以及从性能角度优化代码。

我已经开发了代码,每分钟都使用停止/启动控制执行子程序,但是在XML解析方面遇到了困难。

  1. 文档未加载错误:文档顶层无效
  2. 我的目的是让一个代码通过" row refno"来获得单行代码。然后使用标识符获取所需的列值,这将使我能够灵活地将此代码与实时应用程序生成的类似XML重用。
  3. 到目前为止,我已粘贴代码,我正在使用测试方案,但没有运气。 任何帮助和指导都非常感谢。

    <ddsml xmlns:xsi="http://www.w3.org/2005/XMLSchema-instance" 
           xsi:noNamespaceSchemaLocation="/gpm/include/ddsml.xsd">
    <server>
    <name>AAQ-MMM-Server</name>
    <version>YOTV1R14</version>
    <functionality>3008</functionality>
    <platform>y/OS</platform>
    </server>
    <report>
    <metric id="BPB">
    <description>BPB (Central Processor Complex)</description>
    <format>report</format>
    <numcols>31</numcols>
    </metric>
    <resource>
    <reslabel>,GAQ1,MVS_IMAGE</reslabel>
    <restype>MVS_IMAGE</restype>
    <reslabelurl>,GAQ1,MVS_IMAGE</reslabelurl>
    </resource>
    <time-data>
    <local-start>20010101155200</local-start>
    <local-end>20140708155300</local-end>
    <utc-start>20140708055200</utc-start>
    <utc-end>20140708055300</utc-end>
    <local-prev>20140708155130</local-prev>
    <local-next>20140708155330</local-next>
    <display-start locale="en-us">01/01/2001 15:52:00</display-start>
    <display-end locale="en-us">01/01/2001 15:53:00</display-end>
    <gatherer-interval unit="seconds">60</gatherer-interval>
    <data-range unit="seconds">60</data-range>
    </time-data>
    <caption><var><name>BPBHPNAM</name><value>TH7</value></var><var><name>BPBHMOD</name><value>2817</value></var><var><name>BPBHMDL</name><value>713</value></var><var><name>BPBHCMSU</name><value>1473</value></var><var><name>BPBHWF</name><value>80.0</value></var><var><name>BPBHLMSU</name><value>61</value></var><var><name>BPBHGNAM</name><value>N/A</value></var><var><name>BPBHIMSU</name><value>1133</value></var><var><name>BPBHCAP</name><value>0.0</value></var><var><name>BPBHLMAX</name><value>390</value></var><var><name>BPBHGLIM</name><value>N/A</value></var><var><name>BPBHGL4H</name><value></value></var><var><name>BPBHRMSU</name><value>14400</value></var><var><name>BPBHRGRP</name><value>N/A</value></var><var><name>BPBHGAUN</name><value>N/A</value></var><var><name>BPBHCPU</name><value>00000000000FC826</value></var><var><name>BPBHCPNO</name><value>13</value></var><var><name>BPBHICNO</name><value>0</value></var><var><name>BPBHIFAN</name><value>0</value></var><var><name>BPBHYCFN</name><value>4</value></var><var><name>BPBHIFLN</name><value>0</value></var><var><name>BPBHSUPN</name><value>13</value></var><var><name>BPBHPANO</name><value>16</value></var><var><name>BPBHWAIT</name><value>NO</value></var><var><name>BPBHPMSU</name><value>3</value></var><var><name>BPBHDEDC</name><value>3</value></var><var><name>BPBHDEDA</name><value>0</value></var><var><name>BPBHDEDI</name><value>0</value></var><var><name>BPBHSHRC</name><value>10</value></var><var><name>BPBHSHRA</name><value>0</value></var><var><name>BPBHSHRI</name><value>13</value></var><var><name>BPBHVCPU</name><value>NO</value></var><var><name>BPBHWMGT</name><value>YES</value></var><var><name>BPBHCCAI</name><value>100</value></var><var><name>BPBHCCCR</name><value>0</value></var><var><name>BPBHCUTL</name><value>44.2</value></var><var><name>BPBHAUTL</name><value>0.0</value></var><var><name>BPBHUUTL</name><value>12.7</value></var><var><name>BPBHLUTL</name><value>0.0</value></var><var><name>BPBHFUTL</name><value>0.0</value></var></caption><row refno="1"><col>*DP</col> <col/> <col/> <col/> <col>52.0</col> <col/> <col/> <col>1.8</col> <col>33.8</col> <col>35.5</col> <col>CS</col> <col>49</col> <col>3</col> <col>988</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="2"><col>THB</col> <col>0</col> <col>0</col> <col>NO</col> <col>2.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>CP</col> <col>2</col> <col>0</col> <col>20</col> <col>10.1</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>30720</col> <col/> <col>NO</col> <col/></row>
    <row refno="3"><col>THC</col> <col>0</col> <col>119</col> <col>NO</col> <col>2.0</col> <col>52.3</col> <col>52.4</col> <col>0.0</col> <col>8.1</col> <col>8.1</col> <col>CP</col> <col>2</col> <col>0</col> <col>12</col> <col>6.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>AZZ1</col> <col>SYPLX2S</col> <col>12</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>75776</col> <col/> <col>NO</col> <col/></row>
    <row refno="4"><col>THF</col> <col>0</col> <col>1</col> <col>NO</col> <col>1.0</col> <col>0.8</col> <col>0.8</col> <col>0.0</col> <col>0.1</col> <col>0.1</col> <col>CP</col> <col>1</col> <col>0</col> <col>6</col> <col>6.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>16384</col> <col/> <col>NO</col> <col/></row>
    <row refno="5"><col>TH1</col> <col>0</col> <col>100</col> <col>NO</col> <col>8.0</col> <col>10.8</col> <col>11.0</col> <col>0.2</col> <col>6.6</col> <col>6.8</col> <col>CP</col> <col>8</col> <col>0</col> <col>274</col> <col>34.6</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>AAQ1</col> <col>SPXMY2X</col> <col>330</col> <col>145</col> <col>620</col> <col/> <col/> <col/> <col/> <col>294912</col> <col/> <col>NO</col> <col/></row>
    <row refno="6"><col>TH11</col> <col>0</col> <col>9</col> <col>NO</col> <col>2.0</col> <col>4.0</col> <col>4.1</col> <col>0.0</col> <col>0.6</col> <col>0.6</col> <col>CP</col> <col>2</col> <col>0</col> <col>4</col> <col>4.0</col> <col>0</col> <col>1</col> <col>1</col> <col>TBI1</col> <col>SYPLX2I</col> <col>4</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>16384</col> <col/> <col>NO</col> <col/></row>
    <row refno="7"><col>TH2</col> <col>0</col> <col>106</col> <col>NO</col> <col>8.0</col> <col>11.4</col> <col>11.7</col> <col>0.2</col> <col>7.0</col> <col>7.2</col> <col>CP</col> <col>8</col> <col>0</col> <col>386</col> <col>48.8</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>AAQ3</col> <col>SPXMY2X</col> <col>330</col> <col>145</col> <col>620</col> <col/> <col/> <col/> <col/> <col>294912</col> <col/> <col>NO</col> <col/></row>
    <row refno="8"><col>TH3</col> <col>0</col> <col>42</col> <col>NO</col> <col>4.0</col> <col>9.2</col> <col>9.3</col> <col>0.0</col> <col>2.8</col> <col>2.9</col> <col>CP</col> <col>4</col> <col>0</col> <col>165</col> <col>41.7</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>AAQ5</col> <col>SPXMY2X</col> <col>165</col> <col>60</col> <col>165</col> <col/> <col/> <col/> <col/> <col>131072</col> <col/> <col>NO</col> <col/></row>
    <row refno="9"><col>TH4</col> <col>0</col> <col>0</col> <col>NO</col> <col>3.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>CP</col> <col>0</col> <col>3</col> <col>0</col> <col>100</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>256</col> <col/> <col/> <col/></row>
    <row refno="10"><col>TH6</col> <col>0</col> <col>4</col> <col>NO</col> <col>2.0</col> <col>1.7</col> <col>1.7</col> <col>0.0</col> <col>0.3</col> <col>0.3</col> <col>CP</col> <col>2</col> <col>0</col> <col>30</col> <col>30.3</col> <col>0</col> <col>1</col> <col>1</col> <col>GAQL</col> <col>SPXMY2X</col> <col>30</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>4096</col> <col/> <col>NO</col> <col/></row>
    <row refno="11"><col>TH7</col> <col>0</col> <col>38</col> <col>NO</col> <col>8.0</col> <col>4.2</col> <col>4.2</col> <col>0.0</col> <col>2.6</col> <col>2.6</col> <col>CP</col> <col>8</col> <col>0</col> <col>56</col> <col>7.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>GAQ1</col> <col>SPXMY2X</col> <col>37</col> <col>15</col> <col>70</col> <col/> <col/> <col/> <col/> <col>294912</col> <col/> <col>NO</col> <col/></row>
    <row refno="12"><col>TH8</col> <col>0</col> <col>18</col> <col>NO</col> <col>8.0</col> <col>2.0</col> <col>2.0</col> <col>0.0</col> <col>1.2</col> <col>1.3</col> <col>CP</col> <col>8</col> <col>0</col> <col>18</col> <col>2.2</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>GAQ3</col> <col>SPXMY2X</col> <col>37</col> <col>15</col> <col>70</col> <col/> <col/> <col/> <col/> <col>294912</col> <col/> <col>NO</col> <col/></row>
    <row refno="13"><col>TH9</col> <col>0</col> <col>63</col> <col>NO</col> <col>4.0</col> <col>13.7</col> <col>13.9</col> <col>0.0</col> <col>4.2</col> <col>4.3</col> <col>CP</col> <col>4</col> <col>0</col> <col>17</col> <col>4.3</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col>GAQ5</col> <col>SPXMY2X</col> <col>17</col> <col>6</col> <col>17</col> <col/> <col/> <col/> <col/> <col>196608</col> <col/> <col>NO</col> <col/></row>
    <row refno="14"><col>PHYSICAL</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>1.2</col> <col/> <col>1.5</col> <col>CY</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>0</col> <col/> <col/> <col/></row>
    <row refno="15"><col></col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="16"><col>*YCFPOOL</col> <col/> <col/> <col/> <col>4.0</col> <col/> <col/> <col>0.0</col> <col>99.9</col> <col>99.9</col> <col>IS</col> <col>0</col> <col>4</col> <col>0</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="17"><col>THA</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>99.9</col> <col>99.9</col> <col>0.0</col> <col>50.0</col> <col>50.0</col> <col>IP</col> <col>0</col> <col>2</col> <col>0</col> <col>0.0</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="18"><col>TH5</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>99.9</col> <col>99.9</col> <col>0.0</col> <col>50.0</col> <col>50.0</col> <col>IP</col> <col>0</col> <col>2</col> <col>0</col> <col>0.0</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="19"><col>PHYSICAL</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>0.0</col> <col/> <col>0.0</col> <col>IY</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="20"><col></col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="21"><col>*YCF</col> <col/> <col/> <col/> <col>4.0</col> <col/> <col/> <col>0.0</col> <col>99.9</col> <col>99.9</col> <col>FS</col> <col>0</col> <col>4</col> <col>0</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="22"><col>THA</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>99.9</col> <col>99.9</col> <col>0.0</col> <col>50.0</col> <col>50.0</col> <col>FP</col> <col>0</col> <col>2</col> <col>0</col> <col>100</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="23"><col>TH5</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>99.9</col> <col>99.9</col> <col>0.0</col> <col>50.0</col> <col>50.0</col> <col>FP</col> <col>0</col> <col>2</col> <col>0</col> <col>100</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="24"><col>PHYSICAL</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>0.0</col> <col/> <col>0.0</col> <col>FY</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="25"><col></col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="26"><col>*KPP</col> <col/> <col/> <col/> <col>40.0</col> <col/> <col/> <col>0.4</col> <col>12.6</col> <col>13.0</col> <col>US</col> <col>40</col> <col>0</col> <col>988</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <row refno="27"><col>THB</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>UP</col> <col>2</col> <col>0</col> <col>21</col> <col>13.8</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="28"><col>THC</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>1.4</col> <col>1.5</col> <col>0.0</col> <col>0.2</col> <col>0.2</col> <col>UP</col> <col>2</col> <col>0</col> <col>12</col> <col>7.8</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="29"><col>TH1</col> <col/> <col/> <col>NO</col> <col>6.0</col> <col>9.9</col> <col>10.0</col> <col>0.0</col> <col>4.6</col> <col>4.6</col> <col>UP</col> <col>6</col> <col>0</col> <col>342</col> <col>75.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="30"><col>TH11</col> <col/> <col/> <col>NO</col> <col>2.0</col> <col>0.1</col> <col>0.2</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>UP</col> <col>2</col> <col>0</col> <col>4</col> <col>5.2</col> <col>0</col> <col>1</col> <col>1</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="31"><col>TH2</col> <col/> <col/> <col>NO</col> <col>6.0</col> <col>11.6</col> <col>11.7</col> <col>0.0</col> <col>5.4</col> <col>5.4</col> <col>UP</col> <col>6</col> <col>0</col> <col>342</col> <col>75.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="32"><col>TH3</col> <col/> <col/> <col>NO</col> <col>5.0</col> <col>4.4</col> <col>4.4</col> <col>0.0</col> <col>1.7</col> <col>1.7</col> <col>UP</col> <col>5</col> <col>0</col> <col>171</col> <col>45.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="33"><col>TH7</col> <col/> <col/> <col>NO</col> <col>6.0</col> <col>0.1</col> <col>0.1</col> <col>0.0</col> <col>0.0</col> <col>0.0</col> <col>UP</col> <col>6</col> <col>0</col> <col>32</col> <col>7.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="34"><col>TH8</col> <col/> <col/> <col>NO</col> <col>6.0</col> <col>0.9</col> <col>0.9</col> <col>0.0</col> <col>0.4</col> <col>0.4</col> <col>UP</col> <col>6</col> <col>0</col> <col>32</col> <col>7.0</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="35"><col>TH9</col> <col/> <col/> <col>NO</col> <col>5.0</col> <col>0.7</col> <col>0.7</col> <col>0.0</col> <col>0.3</col> <col>0.3</col> <col>UP</col> <col>5</col> <col>0</col> <col>32</col> <col>8.4</col> <col>N/A</col> <col>N/A</col> <col>N/A</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col>NO</col> <col/></row>
    <row refno="36"><col>PHYSICAL</col> <col/> <col/> <col/> <col/> <col/> <col/> <col>0.3</col> <col/> <col>0.3</col> <col>UY</col> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/> <col/></row>
    <column-headers> <col type="T">BPBPPNAM</col> <col type="N">BPBPDMSU</col> <col type="N">BPBPAMSU</col> <col type="T">BPBPCAPD</col> <col type="N">BPBPLPNO</col> <col type="N">BPBPLEFU</col> <col type="N">BPBPLTOU</col> <col type="N">BPBPPLMU</col> <col type="N">BPBPPEFU</col> <col type="N">BPBPPTOU</col> <col type="T">BPBPIND</col> <col type="N">BPBPLPND</col> <col type="N">BPBPDEDP</col> <col type="N">BPBPWGHT</col> <col type="N">BPBPLPSH</col> <col type="T">BPBPVCMH</col> <col type="T">BPBPVCMM</col> <col type="T">BPBPVCML</col> <col type="T">BPBPOSNM</col> <col type="T">BPBPLPCN</col> <col type="N">BPBPLCIW</col> <col type="N">BPBPLCMW</col> <col type="N">BPBPLCXW</col> <col type="N">BPBPCGNM</col> <col type="N">BPBPCGLT</col> <col type="N">BPBPCGEM</col> <col type="N">BPBPCGEX</col> <col type="N">BPBPCSMB</col> <col type="N">BPBPUPID</col> <col type="T">BPBPCAPI</col> <col type="N">BPBPHWCC</col> </column-headers>
    </report>
    </ddsml>
    
    
    
    
    
    
    /* Code */
    Sub FetchLiveData()
    
    'Declaration section
    Dim CPCxmlDom As MSXML2.DOMDocument
    
    Dim strErrText As String
    Dim xmlPE As MSXML2.IXMLDOMParseError
    
    Dim xresult As MSXML2.IXMLDOMNode
    Dim xentry As MSXML2.IXMLDOMNode
    Dim xChild As MSXML2.IXMLDOMNode
    
    Dim row As Integer, col As Integer
    
    'Initialization
    col = 1
    row = 1
    
    
    Set CPCxmlDom = New MSXML2.DOMDocument
    CPCxmlDom.async = False
    CPCxmlDom.validateOnParse = False
    
     If Not CPCxmlDom.LoadXML("C:TestCPC.xml") Then
     ' The document failed to load.
    
       ' Obtain the ParseError object and format
       Set xmlPE = CPCxmlDom.parseError
       With xmlPE
          strErrText = "Your XML Document failed to load" & _
            "due the following error." & vbCrLf & _
            "Error #: " & .ErrorCode & ": " & xmlPE.reason & _
            "Line #: " & .Line & vbCrLf & _
            "Line Position: " & .linepos & vbCrLf & _
            "Position In File: " & .filepos & vbCrLf & _
            "Source Text: " & .srcText & vbCrLf & _
            "Document URL: " & .URL
        End With
        MsgBox strErrText, vbExclamation
            Set xmlPE = Nothing
     Else
    
        Set xresult = CPCxmlDom.DocumentElement
        Set xentry = xresult.FirstChild
    
        For Each xentry In xresult.ChildNodes
    
                For Each xChild In xentry.ChildNodes
    
                    MsgBox xChild.BaseName & " " & xChild.Text
                row = row + 1
                'col = col + 1
    
                Next xChild
        'row = row + 1
        col = col + 1
        Next xentry
    
     End If
    
    End Sub
    

2 个答案:

答案 0 :(得分:0)

在Excel中,您可以从开发人员导入xsd - &gt;来源,然后从开发人员导入您的xml - &gt;导入,但它不会将您的col元素放在不同的列中,因为它们都具有相同的名称。如果您有Excel 2013,还可以查看FILTERXML公式。 XSLT也是你的选择吗?

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8"/>
    <xsl:template match="/">
        <xsl:text>refno col1    col5</xsl:text>
        <xsl:text>&#10;</xsl:text>
        <xsl:for-each select="ddsml/report/row">
                <xsl:value-of select="@refno"/>
                <xsl:text>  </xsl:text>
                <xsl:value-of select="col[1]"/>
                <xsl:text>  </xsl:text>
                <xsl:value-of select="col[5]"/>
                <xsl:text>&#10;</xsl:text>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

输出结果为:

$ xsltproc serverinfo.xsl serverinfo.xml
refno   col1    col5
1       *DP     52.0
2       THB     2.0
3       THC     2.0
4       THF     1.0
5       TH1     8.0
6       TH11    2.0
7       TH2     8.0
8       TH3     4.0
9       TH4     3.0
10      TH6     2.0
11      TH7     8.0
12      TH8     8.0
13      TH9     4.0
14      PHYSICAL
15
16      *YCFPOOL        4.0
17      THA     2.0
18      TH5     2.0
19      PHYSICAL
20
21      *YCF    4.0
22      THA     2.0
23      TH5     2.0
24      PHYSICAL
25
26      *KPP    40.0
27      THB     2.0
28      THC     2.0
29      TH1     6.0
30      TH11    2.0
31      TH2     6.0
32      TH3     5.0
33      TH7     6.0
34      TH8     6.0
35      TH9     5.0
36      PHYSICAL

答案 1 :(得分:0)

解决了问题,解决方案正在按要求工作

  1. 问题1通过CPCxmlDom.Load加载errtor,修改CPCxmlDom.LoadXML
  2. 问题2为xNode.ChildNodes中的每个xChild运行循环

    Select Case xChild.BaseName
    
        Case "row"
         ActiveWorkbook.Sheets("Data").Range("B" & xlrow).Value = xChild.ChildNodes(0).Text
    end case
    
  3. 感谢您的帮助