は、この単純化しすぎXMLファイルを考えるとあなたがfoo
の値がNil
であることがわかりますオブジェクト属性に値が設定されていないのはなぜですか?</p> <blockquote> <pre><code><Foo>Bar</Foo> </code></pre> </blockquote> <p>そして<code>Foo</code>要素の値を抽出し、このコード:
use XML::Rabbit;
use Data::Dump::Tree;
class RunInfo does XML::Rabbit::Node {
has $.foo is xpath("/Foo");
}
sub MAIN ($file!) {
my $xml = RunInfo.new(file => $file);
dump $xml;
put "-----------------------";
put "Foo is $xml.foo()";
}
を、出力はFoo is Bar
と表示されますが、
.RunInfo @0 ├ $.foo = Nil ├ $.context is rw = .XML::Document @1 │ ├ $.version = 1.0.Str │ ├ $.encoding = Nil │ ├ %.doctype = {0} @2 │ ├ $.root = .XML::Element @3 │ │ ├ $.name is rw = Foo.Str │ │ ├ @.nodes is rw = [1] @4 │ │ │ └ 0 = .XML::Text @5 │ │ │ ├ $.text = Bar.Str │ │ │ └ $.parent is rw = .XML::Element §3 │ │ ├ %.attribs is rw = {0} @7 │ │ ├ $.idattr is rw = id.Str │ │ └ $.parent is rw = .XML::Document §1 │ ├ $.filename = example.xml.Str │ └ $.parent is rw = Nil └ $.xpath is rw = .XML::XPath @9 ├ $.document = .XML::Document §1 └ %.registered-namespaces is rw = {0} @11 ----------------------- Foo is Bar
(免責事項:私は私のコードでは、今日、この動作に出くわしたので、私はQ &スタイルをそれを書きました。その他の回答はようこそ)。
ところで、ここにはXML::RabbitとData::Dump::Treeへのリンクがあります。