-1

我正在使用 XML::Simple 解析数组,它总是给出 No Close 标记标记,而我确定有一个 close 标记...

这是直接从数组打印时的输出

    <ClearQuest db='XXX' login='XXXX' cqtan='1319' client='XXX.com' ip=''>
   <defect id='dts0100' action='view' status='ok'>
     <component>RA_Checks</component>
     <description>Please, discuss before resolution.
 </description>
     <headline>[CSV] Got a warning </headline>
     <id_short>799</id_short>
     <owner>ABC</owner>
     <planned_release.name>2013</planned_release.name>
   </defect>
 </ClearQuest>

`

它总是看不到元素的紧密标签。以下是 Iam 的解析方式:`

 my $a = join("",@cmdout);
   my $ref= XMLin($a);
   print $ref->{ClearQuest}->{defect}-{'id_short'};
   print $ref;

`

谁能帮我解决这个错误!

当我使用 print Dumper \@cmdout 我得到了这个`

   $VAR1 = [
              '<ClearQuest db=\'d1\' login=\'\' cqtan=\'1\' client=\'dhcp-3\' ip=\'1\'>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt\' login=\'\' cqtan=\'13\' client=\'dhcp-3\' ip=\'1\'>
    ',
              '  <defect id=\'dts0100\' action=\'view\' status=\'ok\'>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt\' login=\'\' cqtan=\'1\' client=\'dhcp-3\' ip=\'1\'>
    ',
              '  <defect id=\'dts0100\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'d\' login=\'\' cqtan=\'1\' client=\'dhcp\' ip=\'137.202.34.85\'>
    ',
              '  <defect id=\'dts\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'d\' login=\'\' cqtan=\'1\' client=\'dhcp-3\' ip=\'1\'>
    ',
              '  <defect id=\'dts0100\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt\' login=\'sh\' cqtan=\'13\' client=\'d\' ip=\'\'>
    ',
              '  <defect id=\'dts0100\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances,
    ',
              '
    ',
              'I believe no warning should be produced 
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'\' login=\'s\' cqtan=\'\' client=\'dhcp\' ip=\'1\'>
    ',
              '  <defect id=\'dts0100799428\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instance
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'\' login=\'\' cqtan=\'\' client=\'dhcp-34-85.egc.mentorg.com\' ip=\'1\'>
    ',
              '  <defect id=\'dts\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '
    ',
              'Please, discuss before resolution.
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'d\' login=\'\' cqtan=\'13\' client=\'dhcp-34-\' ip=\'137\'>
    ',
              '  <defect id=\'dts01\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    ',
              'I believe no warning should be produced
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt\' login=\'s\' cqtan=\'131\' client=\'dhcp-34\' ip=\'13\'>
    ',
              '  <defect id=\'dts01\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addressed
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    ',
              '    <headline>[CSV] Got a warning for a missing "Register Address" column.</headline>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'d\' login=\'\' cqtan=\'130\' client=\'dhcp\' ip=\'13\'>
    ',
              '  <defect id=\'dts0100799428\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses fornot appear!
    ',
              '
    ',
              'I believe no warning should be produced when that column
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    ',
              '    <headline>[CSV] Got a warning for a missing "Register Address" column.</headline>
    ',
              '    <id_short>79</id_short>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt1\' login=\\' cqtan=\'\' client=\'dhcp-34-85.egc.mentorg.com\' ip=\'1\'>
    ',
              '  <defect id=\'dts0\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances,
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    ',
              '    <headline>[CSV] Got a warning for a missing "Register Address" column.</headline>
    ',
              '    <id_short></id_short>
    ',
              '    <owner>am</owner>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dts1\' login=\'\' cqtan=\'131\' client=\'dhcp\' ip=\'13\'>
    ',
              '  <defect id=\'dts01\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    ',
              'I believe no warning should be produced
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    ',
              '    <headline>[CSV] Got a warning for a missing "Register Address" column.</headline>
    ',
              '    <id_short>799428</id_short>
    ',
              '    <owner>am</owner>
    ',
              '    <planned_release.name>2013.1</planned_release.name>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dt\' login=\'\' cqtan=\'\' client=\'dhcp-3\' ip=\'13\'>
    ',
              '  <defect id=\'dts0\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '
    ',
              'Please, discuss before resolution.
    ',
              '</description>
    ',
              '    <headline>[CSV] Got a warning for a missing "Register Address" column.</headline>
    ',
              '    <id_short></id_short>
    ',
              '    <owner></owner>
    ',
              '    <planned_release.name>2013.1</planned_release.name>
    ',
              '  </defect>
    '
            ];
    $VAR1 = [
              '<ClearQuest db=\'dts01\' login=\'\' cqtan=\'\' client=\'dhcp-34-...com\' ip=\'1\'>
    ',
              '  <defect id=\'dts010\' action=\'view\' status=\'ok\'>
    ',
              '    <component>RA_Checks</component>
    ',
              '    <description>I have specified addresses for all my register instances
    ',
              '
    ',
              'I believe no warning should be produced 
    ',
              '          '    <id_short>798</id_short>
    ',
              '    <owner>a</owner>
    ',
              '    <planned_release.name>2013.1</planned_release.name>
    ',
              '  </defect>
    ',
              '</ClearQuest>'
            ];

`

4

2 回答 2

2

XML::Simple是解析 XML 的错误选择。使用起来可能远非“简单”,它自己的文档说明了这一点。

不鼓励在新代码中使用此模块。其他模块也可以提供更直接和一致的接口。

但是它非常有能力检测格式错误的 XML,并且您显示的数据很好;如果您将该文字传递给XMLin进行处理,则不会引发错误。

所以你传递的数据不是你想象的那样。我建议你仔细看看你的阵列

use Data::Dumper;
print Dumper \@cmdout;

并且,如果您仍然无法解决问题,请在此处发布该输出以供我们查看。

于 2013-07-14T13:01:38.857 回答
-1

你需要:

$ref->{defect}->{'id_short'};
于 2013-07-14T13:00:58.943 回答