DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Have large XML file need to sort without xsl

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Have large XML file need to sort without xsl

    I have been trying to figure this out for a week, searched Google many times
    - read tons of articles - I just can't get this to work. I have an XML file
    which is generated by an application we use. This XML file loads data into
    a form for the application. the application was written poorly and does not
    allow sorting of the columns on the form. This makes using the form very
    difficult as I need to look through over 500 entries 3 at a time (all the
    form will allow you to display). My goal is to be able to sort this XML
    file so that when the form is opened the entries are sorted already,
    making looking for a particular entry much easier. I cannot change the
    way the app uses the XML so I need to sort the XML file and then place
    it back into the App folder sorted. I tested this by manually sorting 2
    entries in notepad and it does work, but sorting 500+ entries manually
    is not feasible. Ok now here is an example of my XML file listed below:

    <bunch of stuff before the section I need sorted>

    <mailboxes>

    <mailbox>
    <pop_server>111.222.333.444</pop_server>
    <login>username4</login>
    <password>********</password>
    <alternate_address>username4@emailserver</alternate_address>
    <send_to>alternate</send_to>
    </mailbox>

    <mailbox>
    <pop_server>111.222.333.444</pop_server>
    <login>username2</login>
    <password>********</password>
    <alternate_address>username2@emailserver</alternate_address>
    <send_to>alternate</send_to>
    </mailbox>

    <mailbox>
    <pop_server>111.222.333.444</pop_server>
    <login>username1</login>
    <password>********</password>
    <alternate_address>username1@emailserver</alternate_address>
    <send_to>alternate</send_to>
    </mailbox>

    </mailboxes>

    <bunch of stuff at the end>



    I wish to have this sorted by the ALTERNATE_ADDRESS portion of the data.
    I have read so many posts and tried to adapt so many pieces of code to
    fit my needs, but I just can't get this to work. I am a Network Engineer
    who dabbles in code every now and then, but I am certainly not a programmer,
    so please try to post in as simple terms as possible.

    Thanks to anyone who may take the time to read this post, or that tries to
    help me out - I really do appreciate the time & effort.

  2. #2
    Join Date
    May 2009
    Posts
    60
    for sorting xml use xslt

    ther many xslt parser
    use saxon for all operating Systems
    or xmllint

    http://xmlsoft.org/downloads.html

    http://xmlsoft.org/xmllint.html

    http://xmlsoft.org/xmllint.html



    the sort.xsl file
    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output indent="yes" method="xml"/>
    	<xsl:template match="/">
    		<mailboxes>
    			<xsl:apply-templates select="mailboxes"/>
    		</mailboxes>
    	</xsl:template>
    
    	<xsl:template match="mailboxes">
    		<xsl:apply-templates select="mailbox">
    			<xsl:sort select="alternate_address"/>
    		</xsl:apply-templates>
    	</xsl:template>
    
    	<xsl:template match="mailbox">
    		<xsl:copy-of select="."/>
    	</xsl:template>
    </xsl:stylesheet>
    xmllint --output sort.xml sort.xsl unsort.xml


    look in sort.xml when it is execute
    Last edited by xml-looser; 08-29-2009 at 07:48 AM.

  3. #3
    Join Date
    Aug 2009
    Posts
    2
    Thanks so very much - this did the trick...

    Finally the app I have been struggling with for 3 years is now not so bad to use due to the columns being sorted finally.

    I can't tell you how much I appreciate your help....

Similar Threads

  1. How to include XML in XML file?
    By calgarychinese in forum XML
    Replies: 11
    Last Post: 08-22-2006, 07:02 PM
  2. Replies: 0
    Last Post: 09-02-2002, 06:11 AM
  3. XML files vs Database
    By Mansoor in forum XML
    Replies: 8
    Last Post: 08-23-2002, 04:35 PM
  4. Replies: 0
    Last Post: 03-20-2001, 02:11 PM
  5. Display xml file
    By rana in forum XML
    Replies: 5
    Last Post: 12-10-2000, 12:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center