OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Existing libraries/mechanisms for alphabetically sortingan

[ Lists Home | Date Index | Thread Index ]

Peter Loh Yoon Chao wrote:
> 
> I currently have XML files with a flat key-value structure and the elements
> are unsorted and without proper formatting, e.g.
> 
>     <main>
> <e.f.g>
>   <value xml:lang="en">data 2</value>
>         </e.f.g>
>         <a.b.c>
> <value xml:lang="en">data 1</value>
>         </a.b.c>
>         ...
>      </main>
> 
> Are there any existing libraries or mechanisms to do the following?
> - convert the file structure into a hierarchical tree structure
> - alphabetically sorting the individual elements at each level
> - indent the individual nodes properly in the resulting XML file
> 

For unflattening and sorting the data, xslt would probably be a good 
choice (depending on the details of your data and what you want to do). 
  Search the archives of the Mulberry xslt list, and look at Jeni 
Tenison's xslt pages, and Dave Pawson's xslt faq pages.  There have been 
a number of threads of flattening and unflattening xml documents.

http://jenitennison.com/xslt/index.html
http://www.dpawson.co.uk/xsl/xslfaq.html

As for pretty-printing the xml file, it depends on what you want and how 
fussy you are about the appearance, given that it doe snot change the 
xml content of the data.  With xslt, just specifying indent='yes' may 
give you what you want.  Tidy can also be an easy - command line or 
programmable - way to format in a postprocessing step.

Cheers,

Tom P





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS