?
Solved

Sorting XML Attributes and Elements in Perl

Posted on 2007-10-02
2
Medium Priority
?
608 Views
Last Modified: 2009-06-30
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_Policy>
  <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.
0
Comment
Question by:MKrauss
2 Comments
 
LVL 39

Accepted Solution

by:
Adam314 earned 750 total points
ID: 20001291
There are several XML modules that help, it depends on how you want to access the data.
You can take a look at CPAN:
    http://search.cpan.org/search?query=XML&mode=all
0
 
LVL 4

Expert Comment

by:daluu
ID: 20002035
While this isn't the conventional way, I prefer to reorder my XML file before processing it. That way, I can also view it the way I want to process it.

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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question