作者:WXLLXWOO | 来源:互联网 | 2023-05-21 11:58
IhaveaproblemIamhopingsomeonecanhelpwith我有个问题,我希望有人能帮忙……Ihavethefollowingexample
I have a problem I am hoping someone can help with...
我有个问题,我希望有人能帮忙……
I have the following example xml structure:
我有以下示例xml结构:
Damian Conway
0596001738
542
Tom Christiansen
Nathan Torkington
0596003137
964
Mark Phillips
John Chappell
076455106X
392
Code that I thought should work:
我认为应该工作的代码:
use warnings;
use strict;
use XML::LibXML;
my $parser = XML::LibXML->new();
my $xmldoc = $parser->parse_file('/path/to/xmlfile.xml');
my $width = "145";
my $query = "//book/image[\@width/text() = '$width']/author/text()";
foreach my $data ($xmldoc->findnodes($query)) {
print "Results: $data\n";
}
Expected output:
预期的输出:
Damian Conway Tom Christiansen
Damian Conway Tom Christiansen
but I do not get anything returned.
但我没有得到任何回报。
I thought this would match the text content of any "author" elements within a "book" element which also contains an "image" element with an attribute 'width' that has a value of 145.
我认为这将匹配“book”元素中的任何“author”元素的文本内容,该元素还包含一个“image”元素,其属性“width”的值为145。
I'm sure I'm overlooking something very obvious here but cannot work out what I am doing wrong.
我肯定我忽略了一些很明显的东西,但却不能算出我做错了什么。
Your help is much appreciated thanks
非常感谢您的帮助
3 个解决方案