[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Existing libraries/mechanisms for alphabetically sortingan


jeni tenison
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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.