Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6370983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:00:04+00:00 2026-05-25T01:00:04+00:00

Something seems odd here. In the example below, I’m accessing text nodes via an

  • 0

Something seems odd here.

In the example below, I’m accessing text nodes via an XPath query ( //book/isbn/text() ). The text() is necessary to coerce XML::LibXML into allowing me to use the XML::LibXML::Text methods.

To get to the parent node though, I have to invoke the parentNode method twice to get the true parent node (<book> in this case):

use strict;
use warnings;
use XML::LibXML;

my $xml = XML::LibXML->new->parse_string( << 'MAIN' );
  <library>
    <book>
      <title>Perl Best Practices</title>
      <author>Damian Conway</author>
      <isbn>0596001738</isbn>
      <pages>542</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif"
             width="145" height="190" />
    </book>
    <book>
      <title>Perl Cookbook, Second Edition</title>
      <author>Tom Christiansen</author>
      <author>Nathan Torkington</author>
      <isbn>0596003137</isbn>
      <pages>964</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif"
             width="145" height="190" />
    </book>
  </library>
MAIN

foreach my $isbn ( $xml->findnodes( '//book/isbn/text()' ) ) {

    # Do something with $isbn->setData()

    my $book = $isbn->parentNode->parentNode;  # My daddy's daddy is my daddy?
    print $book->toString;
}

Output

<book>
      <title>Perl Best Practices</title>
      <author>Damian Conway</author>
      <isbn>0596001738</isbn>
      <pages>542</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif" width="145" height="190"/>
    </book><book>
      <title>Perl Cookbook, Second Edition</title>
      <author>Tom Christiansen</author>
      <author>Nathan Torkington</author>
      <isbn>0596003137</isbn>
      <pages>964</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gif" width="145" height="190"/>
    </book>

So:

  • is my understanding of XML nodes incorrect in assuming that //isbn and //isbn/text() are the same node, or
  • is this a bug in XML::LibXML‘s parentNode method?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:00:05+00:00Added an answer on May 25, 2026 at 1:00 am

    Each element in a XML document is a node. If that element contains text (e.g. <isbn>019328373476</isbn>), then it is a child node (of type text, as opposed to element) of that element.

    It is not a bug in XML::LibXML’s parentNode method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty certain I'm missing something really obvious here but this seems quite bizarre.
I ran into something that seems odd. SQL Server appears to be rounding some
I have what seems like an odd situation here. I'm launching dialogs from a
I have noticed something odd with linq and the Contains method. It seems to
This behavior seems incredibly odd to me, and I assume I am doing something
I might be missing something, but I'm getting what I think seems an odd
Something seems to be breaking the display of lists ( ul and ol )
I am looking to write something that seems like it should be easy enough,
I am having a heck of time with something that seems rather straightforward but
I was doing some performance metrics and I ran into something that seems quite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.