Hi,

As you're able to load items one by one, it might be easiest to dynamically
create a Objectarray, and the use java.util.Array to sort it. This is
available in from java 1.2 onwards.

so,

import java.util.Arrays;
import java.util.Comparator;

> NodeList PupilList = root.getElementsByTagName("pupil");
> int NumberPupils = PupilList.getLength();

Object[] myObject= new Object[ NumberPupils ];
Node PupilAlone;

> for (int i=0; i<NumberPupils; i++) {
>    PupilAlone = PupilList.item(i);
     myObjectArray[i] = PupilAlone;
}

// create your comparator here.
// you can find information on this in java.util.Comparator

Arrays.sort( myObjectArray, myComparator );

for(int i=0; i<NumberPupils; i++) {
>    traversePupil( (PupilAlone) myObjectArray[i] );
}


do you see what I mean?

                                                                                
                                                  
                    Software AG                                                 
                                                  
                    <[EMAIL PROTECTED]       To:     "'[EMAIL PROTECTED]'" 
<[EMAIL PROTECTED]>                  
                    lag.de>              cc:                                    
                                                  
                                         Subject:     AW: How to order 
alphabetically                                             
                    21/11/2001                                                  
                                                  
                    16:35                                                       
                                                  
                    Please respond                                              
                                                  
                    to                                                          
                                                  
                    xerces-j-user                                               
                                                  
                                                                                
                                                  
                                                                                
                                                  




Hi.

For XML the document order is important, so don't wonder why you get the
data this way.
If you want it different, there are many ways:

- Create your document ordered. XML preserves this order, and you can
retrieve the data ordered again.
  This does not work if you can think of several ways of ordering.
- Use XSLT to change the ordering. There are quite simple statements that
can do what you need.
- Write your own DOM sorter. I cannot remember there is one in libraries
like Xalan or Xerces you can easily use.
  Maybe (and hopefully) I'm wrong?

Hiran

> -----Urspr�ngliche Nachricht-----
> Von: Java Xerces Rule [mailto:[EMAIL PROTECTED]
> Gesendet: Mittwoch, 21. November 2001 17:31
> An: [EMAIL PROTECTED]
> Betreff: How to order alphabetically
>
>
> Hi all!
>
> I'm parsing an XML document:
> ------//-----------
> <table>
>   <pupil>
>     <name></name>
>     <surname></surname>
>   </pupil>
> ...
> </table>
> ----------//---------
>
> I would like to display Pupils' data, but ordering them
> alphabetically by the surname.
>
> I'm trying it by using:
> -----------//----------------
> NodeList PupilList = root.getElementsByTagName("pupil");
> int NumberPupils = PupilList.getLength();
> for (int i=0; i<NumberPupils; i++) {
>    Node PupilAlone = PupilList.item(i);
>    traversePupil(PupilAlone);
>    ...
> ----------//--------------
>
> But they are ordered in the same way they are in the XML
> document.
>
> Any suggestion? Thank you very much.
> ______________________________________________________________
> _________
> Gana un antivirus abriendo tu cuenta de correo gratis en HispaVista.
> http://www.hispavista.com/altacorreo/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




**********************************************************************
This e-mail (including any attachments) is intended only for
the recipient(s) named above. It may contain confidential or
privileged information and should not be read, copied or
otherwise used or disseminated by any unauthorised person.
Any views or opinions expressed are solely those of the author
and do not necessarily represent those of Yes Television
(Europe) Ltd . If you are not the named recipient, please
contact the sender and delete the e-mail from your system.
**********************************************************************


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to