Greetings,

I'm branching out from working with HTML::TreeBuilder::XPath and HTML::Element which I am comfortable with. I am now trying to streamline some existing scripts by using XML::LibXML and XMLL::Element instead since that seems to allow transformation between various instances of XML more easily.

Or maybe not. There are some differences but by and large everything I have tried has gone well, and the parts I have refactored seem to run more quickly, except now I have become stumped by the error produced on line 19 in the script below, "XML::LibXML::Node::addSibling() -- nNode is not a blessed SV reference". How can I get past that and add a node?

#!/usr/bin/perl use XML::LibXML; use XML::Element; use strict; use warnings; # produces the following error: # XML::LibXML::Node::addSibling() -- nNode is not a blessed SV referen +ce ... my $html = XML::LibXML->load_xml( IO => *DATA{IO} ); foreach my $dd ($html->findnodes('//dd[*/*/a[@class="f"]]')) { if (my $f = $dd->find('./*/*/a[@class="f"]/@href')) { print qq(F=$f\n); my $cc = XML::Element->new('dd'); $cc->push_content('foo'); $dd->addSibling($cc); # this line fails } } print $html->toString,"\n"; exit(0); __DATA__ <html><body> <dl> <dd><details><summary>Example</summary> <dl> <dd><details><summary>one <a href="http://localhost/s1" class="s">0</a> <a href="http://localhost/f1" class="f">0</a> </summary></details></dd> <dd><details><summary>two <a href="http://localhost/s2" class="s">1</a> <a href="http://localhost/f2" class="f">1</a> </summary></details></dd> <dd><details><summary>three <a href="http://localhost/s3" class="s">2</a> <a href="http://localhost/f3" class="f">2</a> </summary></details></dd> </dl></details> </dd> </dl> </body></html>

The script successfully selects a specific set of dd elements below but cannot add a sibling to any of them, at least not the ways I've tried so far. I've tried quite a few permutations and variations on the theme, too.


In reply to XML::LibXML::Node::addSibling() -- nNode is not a blessed SV reference ... by mldvx4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.