in reply to Child contains attribute
Howdy Sandorado, welcome to the Monastery!
This is all I have, because I don't know how to go further. (get always the error message: Can_t locate object or reference "getAttribute" via package XML::LibXML::Nodelist)
That's because XML::LibXML::Nodelist does not have that method. That's natural, because objects of this type represent lists of nodes, not individual nodes; what you'd want to do is call ->foreach() on the Nodelist object, and - for each individual node - call ->attributes() and see if the attributes you're looking for are present.
That said, you don't have to do it that way. If you're interested in selecting specific nodes of an XML document, use an XPath expression. XML::LibXML has a ->findnodes method for that that you can call on any node (e.g. the document root); alternatively, use a module like XML::XPath.
The specific XPath expression you'll want depends on what nodes you're looking for, of course, but you might use something like //metadata[@attribute1 and @Attribute2] to select all metadata elements that have both attribute1 and Attribute2 elements (regardless of value).
I recommend taking a look at the XPath spec for more; section 2.5 has a number of useful examples that are much easier to understand than the formal grammar.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Child contains attribute
by Anonymous Monk on Aug 27, 2014 at 13:45 UTC | |
by Anonymous Monk on Aug 27, 2014 at 14:35 UTC |