正在尝试在以下XML文档中查找“the timer”的值:
<ospf3-database-information xmlns="http://xml.juniper.net/junos/11.1R2/junos-routing">
<ospf3-database external-heading="OSPF3">
<lsa-type>Extern</lsa-type>
<lsa-id>0.0.0.1</lsa-id>
<advertising-router>172.27.255.6</advertising-router>
<sequence-number>0x80000001</sequence-number>
<age>1792</age>
<checksum>0x90bd</checksum>
<lsa-length>28</lsa-length>
<ospf3-external-lsa>
<ospf3-prefix>::/0</ospf3-prefix>
<ospf3-prefix-options>0x0</ospf3-prefix-options>
<type-value>1</type-value>
<metric>0</metric>
</ospf3-external-lsa>
<ospf-database-extensive>
<aging-timer junos:seconds="1808">
00:30:08
</aging-timer>
<installation-time junos:seconds="1790">
00:29:50
</installation-time>
<expiration-time junos:seconds="1808">
00:30:08
</expiration-time>
<send-time junos:seconds="1790">
00:29:50
</send-time>
<lsa-changed-time junos:seconds="1790">
00:29:50
</lsa-changed-time>
<lsa-change-count>1</lsa-change-count>
</ospf-database-extensive>
</ospf3-database>
</ospf3-database-information>唯一需要注意的是,只有当"ospf3-prefix“的文本为::/0时,我才需要它。我正在尝试这个xpath:
//x:ospf3-external-lsa[x:ospf3-prefix=\"::/0\"]/ancestor::x:ospf3-database/x:ospf-database-extensive/x:aging-timer使用x来处理perl中的名称空间:
my $xdatav6 = XML::LibXML->load_xml(string => $defv6);
my $dataxv6 = XML::LibXML::XPathContext->new($xdatav6);
$dataxv6->registerNs("x", "http://xml.juniper.net/junos/11.1R2/junos-routing");但这不起作用,似乎当我使用祖先时,它可以获取除"ospf-database-extensive“树下的任何内容之外的所有内容。
发布于 2012-03-24 03:25:39
您显示的XML无效,因为它没有junos:seconds中使用的junos命名空间的URI。我将根标记更改为
xmlns:junos="http://xml.juniper.net/junos/11.1R2/junos-routing"才能让事情运转起来。
这是我见过的最长的XPath表达式,但这行得通!根据需要添加适当的名称空间前缀。
/ospf3-database-information/ospf3-database[ospf3-external-lsa/ospf3-prefix="::/0"]/ospf-database-extensive/aging-timerhttps://stackoverflow.com/questions/9844792
复制相似问题