I have an XML file which has only one node called import. I want to find the href attribute of import. I tried using findnodes(), but that returns a list I would have to search further, so I was hoping there was a way to find a particular node which has only one occurence. I tried getChildrenByTagName but that gives the error
Can't locate object method "getChildrenByTagName" via package "XML::LibXML::Document"
I also tried grep which gives a similar error
Can't locate object method "grep" via package "XML::LibXML::Document"
My XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<resource name="data" type="application/dictionary+xml">
<schema>
<import href="tobefound.xml"/>
</schema>
</resource>
My code so far is
#!/usr/bin/perl
use warnings;
use strict;
use XML::LibXML;
my $name = $ARGV[1];
my $dom = XML::LibXML->load_xml(location => $name);
my @node= $dom->findnodes('//import');
print "List: @node\n";
Please let me know if there is a way to find only one particular node without needing to traverse the whole dom and without having to store it as a list. Thank you.
@node? - tinitaimportin some way? - user1677804