Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Replace xml first id

by marto (Cardinal)
on Apr 22, 2020 at 12:23 UTC ( [id://11115891]=note: print w/replies, xml ) Need Help??


in reply to Replace xml first id

You are trying to alter an attribute:

#!/usr/bin/perl use strict; use warnings; use feature 'say'; use Mojo::DOM; my $xml = '<header> <idset id="100"> <a>item_a</a> <b>item_b</b> </idset> </header>'; my $dom = Mojo::DOM->new->xml(1)->parse( $xml ); # say current attribute value say 'Current value: ' . $dom->at('idset:first-of-type')->attr('id'); # change it to something $dom->at('idset:first-of-type')->attr(id => 'derp'); # dump the whole DOM say $dom->content;

Output:

Current value: 100 <header> <idset id="derp"> <a>item_a</a> <b>item_b</b> </idset> </header>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found