Now the Simple way :)
#! perl -slw use strict; use XML::Simple; my $xml = XMLin( \*DATA, KeepRoot => 1 ); $xml->{policy}{Rule} = $xml->{policy}{policyrules}{Rule}; delete $xml->{policy}{policyrules}; print XMLout( $xml, KeepRoot => 1 ); __END__ <?xml version="1.0" encoding="UTF-8"?> <policy name="Cur_policy" version="3.2.1"> <policyrules> <Rule Action="allow" Enabled="true" RuleID="F68E32"> <source addr="10.4.5.3" srcport="any"/> <dest addr="199.5.4.3" destport="80"/> </Rule> <Rule Action="allow" Enabled="true" RuleID="78E21D"> <source addr="10.4.0.0-10.4.255.255" srcport="any"/> <dest addr="any" destport="80"/> </Rule> </policyrules> </policy>
Produces:
C:\test>xmljunk.pl <policy name="Cur_policy" version="3.2.1"> <Rule Action="allow" Enabled="true" RuleID="F68E32"> <dest addr="199.5.4.3" destport="80" /> <source addr="10.4.5.3" srcport="any" /> </Rule> <Rule Action="allow" Enabled="true" RuleID="78E21D"> <dest addr="any" destport="80" /> <source addr="10.4.0.0-10.4.255.255" srcport="any" /> </Rule> </policy>
In reply to Re: Remove level of elements (preserving their children) in XML::Twig?
by BrowserUk
in thread Remove level of elements (preserving their children) in XML::Twig?
by jdbaldwin23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |