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 |