in reply to Re^12: Update XML Values using two primary keys
in thread Update XML Values using two primary keys
I got the solution to add tags and align. Below is the updated code to add tags and align.
my $dom = 'XML::LibXML'->load_xml(location => 'test.osm'); for my $node ($dom->findnodes('/osm/node')) { my $tag = $node->findnodes('tag[@k="name"]')->[0]; my $key = "$node->{lat}.$node->{lon}"; if (exists $HoH{$key}){ $tag->{v} = $HoH{$key}->{name}; $node->{id} = $HoH{$key}->{id}; delete $HoH{$key}; } } for my $key (keys %HoH){ for my $node ($dom->findnodes('/osm')){ my @lat_lon_key = (split /[.]/, $key); my $lat_key = join('.', @lat_lon_key[0,1]); my $lon_key = join('.', @lat_lon_key[2,3]); my $elm = $dom->createElement('node'); $elm->setAttribute('id', $HoH{$key}->{id}); $elm->setAttribute('lat', $lat_key); $elm->setAttribute('lon', $lon_key); my $tag = XML::LibXML::Element->new("tag"); $tag->setAttribute('k','name'); $tag->setAttribute('v',$HoH{$key}->{name}); $elm->addChild($tag); $node->addChild($elm); } } my $pp = XML::LibXML::PrettyPrint->new(indent_string => " "); $pp->pretty_print($dom); $dom->toFile('new_test.osm');
Thank you very for your help and inputs.
|
|---|