in reply to Regex for XML attributes...
Second off, use XML::Simple instead . . .
The idea is to turn the XML into an anonymous data structure and mangle that instead - all you have to do is iterate thru the 'heading' hashes and remove the level attribute/key - then you create a new data structure whose keys are the concatenation of 'heading' with the level value.use strict; use XML::Simple; local $/; # just so i can slurp __DATA__ my $old_xml = XMLin(<DATA>,forcearray=>1); my $new_xml; foreach my $heading (@{ $old_xml->{'heading'} }) { my $level = delete $heading->{'level'}; $new_xml->{"heading$level"} = $heading; } print XMLout($new_xml); __DATA__ <xml> <heading level="2">Introduction to Arguments</heading> <heading level="3"> <index primary-key="procedures" secondary-key="definition, rest argume +nts in"/> <index primary-key="rest arguments" secondary-key="specifying, in proc +edure definition"/> Specifying Rest Arguments in a Procedure Definition </heading> </xml>
This works, but i only tested it on the XML that i provided, your milleage may vary. ;)
output: <opt> <heading2>Introduction to Arguments</heading2> <heading3> Specifying Rest Arguments in a Procedure Definition <index primary-key="procedures" secondary-key="definition, rest argume +nts in" /> <index primary-key="rest arguments" secondary-key="spec +ifying, in procedure definition" /> </heading3> </opt>
jeffa
A flute with no holes is not a flute . . .
a doughnut with no holes is a danish.
- Basho,
famous philosopher
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Regex for XML attributes...
by tshabet (Beadle) on Aug 23, 2001 at 23:54 UTC | |
by jeffa (Bishop) on Aug 24, 2001 at 00:00 UTC | |
by tshabet (Beadle) on Aug 24, 2001 at 02:24 UTC |