Oh Wise Monks --

I've tried it 10 different ways, and I still can't manage to replace a node in an XML::LibXML::Document. The document ($results) is the output of an XML::LibXSLT stylesheet transformation, and all I want to do is turn any text inside of <hti:wrap></hti:wrap> tags into a text node. Unfortunately, my replaceChild calls are simply ignored; the old nodes remain and the new ones vanish.

Using replaceNode, insertBefore, or insertAfter instead gives me "Use of uninitialized value in subroutine entry". addChild does put the new text nodes into the tree, but appendChild is ignored entirely.

my $results = $stylesheet->transform($source); # Now grab any elements in our namespace my @nodelist = $results->getElementsByTagNameNS($XMLNS, "*"); foreach my $node (@nodelist) { my $newnode; switch ($node->localname()) { case('wrap') { # Pass this all through the Text::Wrap engine. my $sourcetext = $node->textContent(); my $tab = $node->getAttribute('tab') || "\t"; my $first_tab = $node->getAttribute('firsttab') || $tab; my $wrapped_text = wrap($first_tab, $tab, $sourcetext); $newnode = XML::LibXML::Text->new($wrapped_text); } else { die "Unknown processing directive $XMLNS:" . $node->localn +ame() . "\n"; } } if (defined $newnode) { my $parent = $node->parentNode(); $parent->replaceChild($newnode, $node); } }

Any help would be greatly appreciated. I'm running this under Windows XP; not quite sure what problems libxml may have for me this way.

Thanks,
Rob


In reply to replaceChild in LibXML by rgaddi

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.