$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:
In reply to Re^2: XML::LibXML - How to extract an element including the elements within?
by haukex
in thread XML::LibXML - How to extract an element including the elements within?
by TravelAddict
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |