一部は次のようになります。XML :: Twigはいくつかの要素を無視していますか? 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>
私のコードは次のとおりです。<text>Special implements for lifting subsoil layers</text>
<ipcEntry kind="2" symbol="A01B0013100000" ipcLevel="A" entryType="K" lang="EN" nocore="yes">
は別のサブipcEntryを持っているので、私はそのを推測:
#!/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