Don't you need a call to XML::LibXML::XPathContext->new there somewhere, passing the fragment node created by parse_balanced_chunk?

Honestly I don't know, since I'm beginning with all this XML::LibXML stuff.

Just add your new items, and leave the old ones there too, for as long as you want. [...] "a certain RSS reader has a certain lookup rate and I need to match that"

Of course I wasn't going to match Google Reader's polling time, but take the opportunity to implement an expiry time of a couple of weeks or so.

I just discovered I can use a DOM-like interface, and quickly went on this road. However I found another segfault condition. I'm going to notify the module's author but first I would like to share the offending code with you monks, so I don't send them a suboptimal snippet. This is it:

use warnings; use strict; use XML::LibXSLT; use XML::LibXML; my $parser = XML::LibXML->new; my $xslt = XML::LibXSLT->new; ## original web page my $xml_src = $parser->parse_html_string (<<'EOT'); <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>foo</title> </head> <body> <p>foo</p> </body> </html> EOT ## which we will "transform" my $stylesheet = $xslt->parse_stylesheet ($parser->parse_string (<<'EO +T')); <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" indent="yes" xmlns:xsl="http://www.w3.or +g/1999/XSL/Transform"> <xsl:template match="/"> <channel> <item> <title>one item</title> </item> </channel> </xsl:template> </xsl:stylesheet> EOT my $parsed = $stylesheet->transform ($xml_src); ## we'll move this item to another document my $item = ($parsed->getElementsByTagName ('item'))[0]; $item->unbindNode; ## this is the other document: my $saved = $parser->parse_string (<<'EOT'); <?xml version="1.0"?> <channel> <item> <title>other item</title> </item> </channel> EOT my $ch = ($saved->findnodes ('/channel'))[0]; my $addto = ($ch->findnodes ('item'))[0]; $ch->insertBefore ($item, $addto); print "going to boom...\n"; END { print "unreached\n"; }

In particular I'm concerned about those (findnodes)[0]. I tried a couple of other approaches but didn't find anything that returned only the first element. The XSLT transformation does nothing interesting but is actually needed to crash the program.

--
David Serrano


In reply to Re^2: Extracting elements from an XML chunk leads to crash by Hue-Bond
in thread Extracting elements from an XML chunk leads to crash by Hue-Bond

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.