【问题标题】:parsing an XML file and filling with some data from another file解析 XML 文件并填充来自另一个文件的一些数据
【发布时间】:2013-11-28 18:30:31
【问题描述】:

我有一个包含一些标签和值的 XML 文件。

<component id="system.core0.icache" name="icache">
    <param name="icache_config" value="65536,64,2,1,1,2,64,0"/>
    <stat name="read_accesses" value="526692.38"/> 
    <stat name="read_misses" value="2646.34"/>                                 
        <stat name="conflicts" value="2404.67"/>
</component>
<component id="system.core0.dcache" name="dcache">
    <param name="dcache_config" value="65536,64,2,1,1,2,64,0"/>
    <stat name="read_accesses" value="326692.38"/> 
    <stat name="read_misses" value="1646.34"/>                                 
        <stat name="conflicts" value="4404.67"/>
</component>

在另一个文件中,我有另一种格式的值。例如

 L1D:size 65536
 L1I:size 65536
 L1D:access 526692.38
 L1D:miss 2646.34
 L1D:conflict 2404.67
 L1I:access 326692.38
 L1I:miss 1646.34
 L1I:conflict 4404.67

我想要做的是编写一个基于字典的解析器,将值从 stat 文件复制到 XML 文件。例如

 L1D:size   ->   component.id = "system.core0.dcache" , fill the first value of param "dcache_config"

 L1I:access ->   component.id = "system.core0.icache" , fill the stat value of "read_accesses"

我已经搜索过,但解析 XML 文件似乎意味着从 XML 文件中提取值。但我不想那样。

我该怎么做?

【问题讨论】:

    标签: xml parsing xml-parsing


    【解决方案1】:

    听起来像是 SAX 解析器的解决方案。

    while next element
        compare attributes and content
        if necessary then replace
        output
    end
    

    人们会想到 Ruby 或 Perl 作为工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      • 2022-06-17
      • 2011-11-05
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 2017-10-12
      相关资源
      最近更新 更多