michael99 has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I would like to replace the top id of my xml file. But somehow I did not even success to get it. My code below works for other child nodes but not the id. Need help.
Here is my xml file:
Here is my code:<header> <idset id="100"> <a>item_a</a> <b>item_b</b> </idset> </header>
#!/usr/bin/perl use strict; use warnings; use feature 'say'; use XML::LibXML; my $file = 'test.xml'; #my $node; my $parser = XML::LibXML->new(); my $doc = $parser->load_xml(location => $file); my($object11) = $doc->findnodes('/header/idset'); say 'a: ',$object11->findvalue('./a'); say 'b: ',$object11->findvalue('./b'); say 'id: ',$object11->findvalue('./id');
Current Result:
a: item_a
b: item_b
id:
Expecting Result:
a: item_a
b: item_b
id: 100
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Replace xml first id
by choroba (Cardinal) on Apr 22, 2020 at 13:30 UTC | |
|
Re: Replace xml first id
by marto (Cardinal) on Apr 22, 2020 at 12:23 UTC | |
|
Re: Replace xml first id
by hippo (Archbishop) on Apr 22, 2020 at 12:35 UTC | |
|
Re: Replace xml first id
by Corion (Patriarch) on Apr 22, 2020 at 12:23 UTC | |
|
Re: Replace xml first id
by marto (Cardinal) on Apr 22, 2020 at 12:14 UTC | |
by michael99 (Acolyte) on Apr 22, 2020 at 12:19 UTC |