2013-07-14 74 views
-1

我使用XML ::簡單解析的陣列,它總是給沒有關閉標籤標記,而我肯定存在着密切的標籤簡單...沒有結束標記標記在XML ::在Perl

下面是當從陣列 '

<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> 

`

它總是沒有看到的元素的關閉標籤直接印刷輸出。 這裏是如何蔭解析: `

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

`

任何人都可以請幫我這個錯誤!

當我用過的打印翻斗車\ @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>' 
      ]; 

`

+0

你對這段代碼有什麼輸出? – gangabass

+0

「print」語句的輸出是什麼? – Bill

+0

現在檢查我編輯它 –

回答

-1

您需要:

$ref->{defect}->{'id_short'}; 
+0

我不認爲這將解決一個解析錯誤! – Borodin

+0

無法正常工作 –

2

XML::Simple是用於解析XML一個不錯的選擇。它可能遠非「簡單」使用,其自己的文檔說明了這一點。

不鼓勵在新代碼中使用此模塊。其他模塊可提供更直接和一致的接口。

但是它能夠檢測格式不正確的XML,並且顯示的數據很好;如果您將該文字文本傳遞給XMLin進行處理,則不會產生錯誤。

所以你傳遞的數據不是你認爲的數據。我建議你把你的陣列的密切關注與

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

,如果你仍然不能解決問題,然後在這裏發表的是輸出讓我們一起來看看。

+0

請檢查我的帖子,,我使用print Dumper \ @cmdout –

+0

的輸出對它進行了更新。這是'print Dumper @ cmdout'的輸出。請添加反斜槓。 – Borodin

+0

但是,這些數據也很好,'XMLin'對此非常滿意。不知何故,你正在用'XMLin'處理你沒有顯示的東西。您可能需要顯示完整的代碼。 – Borodin