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.
|