일부는 다음과 같습니다XML :: 나뭇 가지가 일부 요소를 무시하고 있습니까? 는 XML의
<ipcEntry kind="1" symbol="A01B0013080000" ipcLevel="A" entryType="K" lang="EN" nocore="yes">
<textBody>
<title>
<titlePart>
<text>for working subsoil</text>
</titlePart>
</title>
</textBody>
<ipcEntry kind="2" symbol="A01B0013100000" ipcLevel="A" entryType="K" lang="EN" nocore="yes">
<textBody>
<title>
<titlePart>
<text>Special implements for lifting subsoil layers</text>
</titlePart>
</title>
</textBody>
<ipcEntry kind="3" symbol="A01B0013120000" ipcLevel="A" entryType="K" lang="EN" nocore="yes">
<textBody>
<title>
<titlePart>
<text>Means for distributing the layers on the surface</text>
</titlePart>
</title>
</textBody>
</ipcEntry>
</ipcEntry>
</ipcEntry>
내 코드는 다음과 같습니다 <ipcEntry kind="2" symbol="A01B0013100000" ipcLevel="A" entryType="K" lang="EN" nocore="yes">
다른 하위 ipcEntry을 가지고 있기 때문에 <text>Special implements for lifting subsoil layers</text>
가 나는 그것의 추측 :
#!/usr/bin/perl
use strict;
use warnings;
use XML::Twig;
use Data::Dumper;
my $twig_handlers = { 'ipcEntry' => \&ipcEntrySub };
my $file = 'A01B.xml';
my $twig= new XML::Twig(twig_handlers => $twig_handlers);
$twig->parsefile($file);
#$twig->print;
sub ipcEntrySub {
my ($twig_obj, $element) = @_;
print $element->{'att'}->{'symbol'} . "\n";
print "Kind: $element->{'att'}->{'kind'}\n";
print $element->text . "\n";
print "###########################################\n";
$twig_obj->purge;
}
나는 텍스트를 얻을하지 못할 것 같다.
나는 <text>Means for distributing the layers on the surface</text>
을 얻을 수 있습니다.
내가 뭘 잘못하고 있니?
감사의 XML에서
정확히 출력을 원하십니까? –
기본적으로 각 요소의 속성과 함께 모든 요소를 인쇄합니다. –
snoofkin
제거하면 현재 요소 앞의 모든 요소가 해제됩니다. 요소의 부모 만 비워 둡니다. 즉, 여전히 속성에 액세스 할 수 있지만 모든 내용은 손실됩니다. 그래서 정말로 삭제하면 여기에 원하는 것입니다. – mirod