http://qs321.pair.com?node_id=1212599


in reply to Parsing and manipulating XML

The cow says, "Mooooooooooo…" :P

use strictures; use XML::LibXML; my $doc = XML::LibXML->load_xml( IO => \*DATA ); my $text = [ $doc->findnodes('/Build-Doc/Build/text()[1]') ]->[0]; my $value = $text->data; $value =~ s/text/TACOS/; $text->setData($value); print $doc; __END__ <Build-Doc> <Build> text.mak <Targets>all</Targets> <Nmake></Nmake> </Build> </Build-Doc>

You can work directly with text as XML nodes. Just find the right xpath in your case to it or, if necessary, to iterate over the text items (my example just grabs the first one and puts it in a scalar instead of an array of found nodes). Update: s/list/array/ + missing article.

Replies are listed 'Best First'.
Re^2: Parsing and manipulating XML
by hoppfrosch (Scribe) on Apr 11, 2018 at 08:07 UTC
    Great - exactly what I was looking for! Thanks for your help - greatly appreciated
A reply falls below the community's threshold of quality. You may see it by logging in.