|
Posted by Fergus McMenemie on December 16, 2007, 5:55 pm
Please log in for more thread options
> fergus@twig.demon.co.uk (Fergus McMenemie) wrote:
> > The following test script is not doing what I expect. It must be
> > a bug:-) The docs I have seen state that "In a SCALAR context
> > getElementsByTagName returns a XML::LibXML::NodeList object.
> > Instead I see it returning a string of the combined text objects
> > from all the child nodes.
> Exactly where are you "seeing" this?
Here is what I see when I run the test script:-
./libxmltest.pl
44444444444444444444444444444444444444444444444444
x=Bactrian CamelDromedary, or Arabian CamelLlamaGuanacoVicuna
y=Bactrian CamelDromedary, or Arabian CamelLlamaGuanacoVicuna
z=XML::LibXML::Element=SCALAR(0x18427a4)
Bactrian Camel (Camelus bactrianus) endangered
Dromedary, or Arabian Camel (Camelus dromedarius) no special status
Llama (Lama glama) no special status
Guanaco (Lama guanicoe) special concern
Vicuna (Vicugna vicugna) endangered
> Where can we obtain camelids.xml in order to repeat your example?
> (I've looked at the web site you linked to, and if it has it then
> it isn't obvious.)
Sorry about that. I think it is in the zip file. However it is simpler
to get it from
http://search.cpan.org/src/KHAMPTON/XML-SemanticDiff-0.95/eg/camelids.xm
l
> > my $root = $tree->getDocumentElement;
> >
> > my $x=($root->getElementsByTagName("common-name"));
> > print "\nx=$x\n"; # should be number of elements in an Element array..
> > # i think!
> Despite the parenthesis, the method is called in a scalar context. So
> it should behave identically to the next piece of code.
Yep. Ok.
> > my $y=$root->getElementsByTagName("common-name");
> > print "\ny=$y\n"; # should be a NodeList
>
> Unless you know there is no stringification overload for NodeList, then
> this print statement doesn't tell you much of anything about what $y
> actually is. Try using Data::Dumper instead.
Tomorrow!
> In any event, you have told us neither what you expected to see nor what
> you actually did see, I have no idea how to go about explaining this
> invisible and possibly nonexistent discrepancy.
I expected to see something similar to:-
44444444444444444444444444444444444444444444444444
x=XML::DOM::NodeList=ARRAY(0x18bb880)
y=XML::DOM::NodeList=ARRAY(0x180127c)
z=XML::DOM::Element=ARRAY(0x18fa3bc)
...... rest snipped....
|