Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I want to make sure the element is unique before it added to the DOM tree. I am using older XML::LibXML which have getElementsById only(1.5x), so I call the getElementsById (I want to use something newer but I can't):

my $elem = $doc->getElementsById($id);
then I use the defined($elem) to see the elem is defined or not, and it always return false even 2 id is identical. How can I check the $elem is a Element or not?

*by the way, the id contains a dot (.), does it matter?

  • Comment on XML::LibXML question: How can I know there is duplicate element exist?
  • Download Code

Replies are listed 'Best First'.
Re: XML::LibXML question: How can I know there is duplicate element exist?
by Anonymous Monk on Mar 04, 2008 at 17:20 UTC

    Check this post: XML::LibXML getElementsById problem

    You may be get into the trouble of DTD, you need to declare the attribute id is type ID in order to make the getElementsById (or getElementById) work in libXML (XML::Twig is much smarter that it will assume id is type ID, so use the xml:id as the first reply suggest.