in reply to Re: XML::LibXML - How to extract an element including the elements within?
in thread XML::LibXML - How to extract an element including the elements within?

$string =~ s/^<[^>]+>//; $string =~ s/<[^>]+>$//;

No, please don't use regular expressions to parse XML...

An alternative to what poj showed with XML::LibXML::DocumentFragment:

use warnings; use strict; use XML::LibXML; my $doc = XML::LibXML->load_xml(string => q{<doc><text>From mobile, <ph1 i="1" type="33" x="1"/>dial<ph2 i=" +1"/> this number:</text></doc>}); for my $node ($doc->findnodes('/doc/text')) { my $frag = $doc->createDocumentFragment; $frag->appendChild($_->cloneNode(1)) for $node->childNodes; print $frag, "\n"; } __END__ From mobile, <ph1 i="1" type="33" x="1"/>dial<ph2 i="1"/> this number:

Replies are listed 'Best First'.
Re^3: XML::LibXML - How to extract an element including the elements within?
by TravelAddict (Acolyte) on May 10, 2019 at 19:44 UTC

    Hello haukex

    I agree with you regarding the use of RE in this case. I was trying to avoid this, and got 2 good working solutions. I preferred the one from poj because it's simpler, however I'm sure that if I explore and understand more your solution I would find some possible ways to solve other issues that I've not met yet.

    Have a great day too!

    TA