Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Parsing and manipulating XML

by Your Mother (Bishop)
on Apr 09, 2018 at 16:33 UTC ( #1212599=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1212599]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2020-12-04 02:17 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (58 votes). Check out past polls.