From: Mike Taylor Date: Mon, 24 Jul 2006 16:44:00 +0000 (+0000) Subject: Initial version of code in append_entry() to make the container X-Git-Tag: CPAN-v1.02~54^2~1102 X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=commitdiff_plain;h=acc9fdde66959c0e1faa75d6e8ca2936c18fc9f4;hp=d3d987e7e5121e6a789880f5f99aba07ad942531 Initial version of code in append_entry() to make the container element if it doesn't already exist. --- diff --git a/lib/ZOOM/IRSpy/Record.pm b/lib/ZOOM/IRSpy/Record.pm index 3369948..2f67dc1 100644 --- a/lib/ZOOM/IRSpy/Record.pm +++ b/lib/ZOOM/IRSpy/Record.pm @@ -1,4 +1,4 @@ -# $Id: Record.pm,v 1.7 2006-07-24 15:25:51 mike Exp $ +# $Id: Record.pm,v 1.8 2006-07-24 16:44:00 mike Exp $ package ZOOM::IRSpy::Record; @@ -71,13 +71,21 @@ sub append_entry { my @nodes = $xc->findnodes($xpath); if (@nodes == 0) { - ZOOM::Log::log("irspy", "no matches for '$xpath': can't append"); - return; - } elsif (@nodes > 1) { - ZOOM::Log::log("irspy", scalar(@nodes), - " matches for '$xpath': using first"); + # Make the node that we're inserting into, if possible. A + # fully general version would work its way through each + # component of the XPath, but for now we just treat it as a + # single chunk to go inside the top-level node. + $this->_half_decent_appendWellBalancedChunk($root, + "<$xpath>"); + @nodes = $xc->findnodes($xpath); + die("still no matches for '$xpath' after creating: can't append") + if @nodes == 0; } + ZOOM::Log::log("irspy", + scalar(@nodes), " matches for '$xpath': using first") + if @nodes > 1; + my $node = $nodes[0]; # $node ISA XML::LibXML::ElementXML::LibXML::Element $this->_half_decent_appendWellBalancedChunk($node, $frag);