MKrauss
asked on
Sorting XML Attributes and Elements in Perl
I need to use a xml configuration file where it's most important to get the data collected in order,
the xml file looks like:
<?xml version="1.0"?>
<ROOT>
<Def_Policy>DROP</Def_Poli cy>
<Def_Parameters>true</Def_ Parameters >
<!-- Comment
Any freetext
-->
<POLICY_A Name="Any Name" Enabled="1">
<ADVICE>any advisory</ADVICE>
<ADVICE>any advisory</ADVICE>
</POLICY_A>
<POLICY_B Name="Any Name" Enabled="1">
<ADVICE>any advisory</ADVICE>
<ADVICE>any advisory</ADVICE>
<SUB Enabled="1">
<SUB_ADVICE_A>OUTPUT</SUB_ ADVICE_A>
<SUB_ADVICE_A>OUTPUT</SUB_ ADVICE_A>
</SUB>
</POLICY_B>
<POLICY_A Name="Any other Name" Enabled="1">
<ADVICE>any other advisory</ADVICE>
<ADVICE>any other advisory</ADVICE>
</POLICY_A>
</ROOT>
How can i read this xml file into a structured hash in order ?
Usualy xml::simple is prefered but will not make it because it is somehow not made for ordering
any elements.
thx.
the xml file looks like:
<?xml version="1.0"?>
<ROOT>
<Def_Policy>DROP</Def_Poli
<Def_Parameters>true</Def_
<!-- Comment
Any freetext
-->
<POLICY_A Name="Any Name" Enabled="1">
<ADVICE>any advisory</ADVICE>
<ADVICE>any advisory</ADVICE>
</POLICY_A>
<POLICY_B Name="Any Name" Enabled="1">
<ADVICE>any advisory</ADVICE>
<ADVICE>any advisory</ADVICE>
<SUB Enabled="1">
<SUB_ADVICE_A>OUTPUT</SUB_
<SUB_ADVICE_A>OUTPUT</SUB_
</SUB>
</POLICY_B>
<POLICY_A Name="Any other Name" Enabled="1">
<ADVICE>any other advisory</ADVICE>
<ADVICE>any other advisory</ADVICE>
</POLICY_A>
</ROOT>
How can i read this xml file into a structured hash in order ?
Usualy xml::simple is prefered but will not make it because it is somehow not made for ordering
any elements.
thx.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To do that use XSLT to transform the XML, then you can process the XML from there or save it to file then do what you want with it. To use XSLT with Perl, you can look into XML::LibXSLT and XML::LibXML. There may be other libraries as well, those two are the ones I've used for XSLT transformation.