使用Perl提取XML标签 [英] Extract XML tags using Perl

查看:110
本文介绍了使用Perl提取XML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Perl脚本来分隔XMl标签.例如:

I need a Perl script to separate XMl tags. For Example:

<bgtres>
 <resume key='267298871' score='5'>
 <xpath path='xpath://resume'>
 <resume canonversion='2' dateversion='2' present='734060'>........... </resume></xpath></resume>
</bgtres>

在这个XML文件中,我需要将简历标记下的内容(在xpath内)分开,应该将出现在xpath之后的resume标签单独从一堆CV中提取出来.我需要在Perl脚本中执行此操作.

In this XML file i need to separate the things under the resume tag (inside the xpath), the resume tag that appears after the xpath should alone to extrated from a bundle of CV's. I need to do this in Perl Script.

任何人都可以给我提示或编码以完成此过程.我需要Perl脚本来执行此过程

Can anyone please give me an hint or coding to do this process. I need the Perl script for doing this process

预先感谢

推荐答案

  • 请参见 XML :: Twig -一个perl模块 用于处理大型XML文档 树模式.
  • XML :: Simple -易于使用的API 维护XML(特别是esp配置文件)
    • see XML::Twig - A perl module for processing huge XML documents in tree mode.
    • or XML::Simple - Easy API to maintain XML (esp config files)
    • 喜欢

      use strict;
      use warnings;
      use XML::Simple;
      use Data::Dumper;
      
      my $xml = q~<?xml version='1.0'?>
      <bgtres>
       <resume key='267298871' score='5'>
        <xpath path='xpath://resume'>
         <resume canonversion='2' dateversion='2' present='734060'>
         </resume>
        </xpath>
       </resume>
      </bgtres>~;
      
      print $xml,$/;
      
      my $data = XMLin($xml);
      
      print Dumper( $data );
      
      foreach my $test (keys %{$data->{resume}{xpath}{resume}}){
              print"$test : $data->{resume}{xpath}{resume}->{$test}\n";
      }
      

      输出:

      <?xml version='1.0'?>
      <bgtres>
       <resume key='267298871' score='5'>
        <xpath path='xpath://resume'>
         <resume canonversion='2' dateversion='2' present='734060'>
         </resume>
        </xpath>
       </resume>
      </bgtres>
      $VAR1 = {
                'resume' => {
                            'xpath' => {
                                       'resume' => {
                                                   'dateversion' => '2',
                                                   'canonversion' => '2',
                                                   'present' => '734060'
                                                 },
                                       'path' => 'xpath://resume'
                                     },
                            'score' => '5',
                            'key' => '267298871'
                          }
              };
      dateversion : 2
      canonversion : 2
      present : 734060
      

      这篇关于使用Perl提取XML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆