You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Jacob Danner <ja...@gmail.com> on 2008/10/10 18:34:19 UTC

Re: sorting xml data in alphabetical order

Passing on the the user list since this is more of a user question.
AFAIK, xmlbeans provides no way to do this internally so you are going
to need to manually sort the array before you set the value of
country. The JDK provides Arrays.sort, but you can investigate using
other sort routines.

HTH,
-jacobd


On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
>
> Hi,
>
>  Using the jar of the xsd i was able to create an xml file & read it. Now
> can anyone pls let me know how to sort the xml file in alphabetical order
> including the parent & its child nodes. My xml file structure is like this:
>
> <country name="India>
>    <state>Goa</state>
>    <state>Rajastan</state>
>    <state>Bhopal</state>
> </country>
> <country name="America">
>    <state>Texas</state>
>    <state>Washington</state>
>    <state>Maryland</state>
>    <state>Alaska</state>
> </country>
>
>
> Expected Result:
> -----------------
> <country name="America">
>    <state>Alaska</state>
>    <state>Maryland</state>
>    <state>Texas</state>
>    <state>Washington</state>
> </country>
> <country name="India>
>    <state>Bhopal</state>
>    <state>Goa</state>
>    <state>Rajastan</state>
> </country>
>
>
> Thanks in Advance.
> Rauf Khan
>
> --
> View this message in context: http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp19920246p19920246.html
> Sent from the Xml Beans - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: sorting xml data in alphabetical order

Posted by Gustavo Aquino <aq...@gmail.com>.
Use XQuery to do this.

On Fri, Oct 10, 2008 at 1:34 PM, Jacob Danner <ja...@gmail.com>wrote:

> Passing on the the user list since this is more of a user question.
> AFAIK, xmlbeans provides no way to do this internally so you are going
> to need to manually sort the array before you set the value of
> country. The JDK provides Arrays.sort, but you can investigate using
> other sort routines.
>
> HTH,
> -jacobd
>
>
> On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
> >
> > Hi,
> >
> >  Using the jar of the xsd i was able to create an xml file & read it. Now
> > can anyone pls let me know how to sort the xml file in alphabetical order
> > including the parent & its child nodes. My xml file structure is like
> this:
> >
> > <country name="India>
> >    <state>Goa</state>
> >    <state>Rajastan</state>
> >    <state>Bhopal</state>
> > </country>
> > <country name="America">
> >    <state>Texas</state>
> >    <state>Washington</state>
> >    <state>Maryland</state>
> >    <state>Alaska</state>
> > </country>
> >
> >
> > Expected Result:
> > -----------------
> > <country name="America">
> >    <state>Alaska</state>
> >    <state>Maryland</state>
> >    <state>Texas</state>
> >    <state>Washington</state>
> > </country>
> > <country name="India>
> >    <state>Bhopal</state>
> >    <state>Goa</state>
> >    <state>Rajastan</state>
> > </country>
> >
> >
> > Thanks in Advance.
> > Rauf Khan
> >
> > --
> > View this message in context:
> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp19920246p19920246.html
> > Sent from the Xml Beans - Dev mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> > For additional commands, e-mail: dev-help@xmlbeans.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

RE: sorting xml data in alphabetical order

Posted by Radu Preotiuc-Pietro <ra...@oracle.com>.
Hello everyone,

I have just added a new sample showing how to do sorting of elements using XmlCursor; given that this seems to be potentially useful to a few people (the sample can be used as-is) and it is a good example of how to use XmlCursor's moveXml() capability.

Look for samples/XmlSort (you need SVN repository access) and then check out the README.

Radu 

> -----Original Message-----
> From: Radu Preotiuc-Pietro [mailto:radu.preotiuc-pietro@oracle.com] 
> Sent: Monday, January 05, 2009 10:15 PM
> To: dev@xmlbeans.apache.org
> Subject: RE: sorting xml data in alphabetical order
> 
> You could post the XQuery you used and we could try to take a 
> look at it and see what's wrong. Or, in the time that it will 
> take you to debug it, you can learn to use XmlCursor and 
> implement the functionality that way.
> 
> Radu 
> 
> > -----Original Message-----
> > From: Rauf khan [mailto:forum.khan@gmail.com]
> > Sent: Tuesday, December 16, 2008 12:37 AM
> > To: dev@xmlbeans.apache.org
> > Subject: Re: sorting xml data in alphabetical order
> > 
> > 
> > I was trying with the examples given at 
> > http://www.yukonxml.com/articles/xquery/ by using saxon8.jar.
> > Iam able to sort only ONE time means i can sort by COUNTRY & not by 
> > STATE & vise versa also a part of the xml code will be 
> missed in the 
> > output.
> > 
> > Input XML File: countryinfo.xml
> > <?xml version="1.0" encoding="UTF-8"?> <World>
> >     <Country name="Pakistan">
> >         <State name="Karachi" population="999"/>
> >         <State name="Islamabad" population="900"/>
> >         <State name="Rawalpandi" population="909"/>
> >     </Country>
> >     <Country name="India">
> >         <State name="Bangalore" population="100"/>
> >         <State name="AP" population="200"/>
> >         <State name="Madras" population="300"/>
> >         <State name="Delhi" population="600"/>
> >     </Country>
> > </World>
> > 
> > Query to sort by Country:
> > Query: for $country in doc("countryinfo.xml")/World/Country
> >           order by $country/@name ascending
> >           return $country
> > 
> > OutPut:
> > <?xml version="1.0" encoding="UTF-8"?> <Country name="India">
> >         <State name="Bangalore" population="100"/>
> >         <State name="AP" population="200"/>
> >         <State name="Madras" population="300"/>
> >         <State name="Delhi" population="600"/>
> >     </Country>
> > <Country name="Pakistan">
> >         <State name="Karachi" population="999"/>
> >         <State name="Islamabad" population="900"/>
> >         <State name="Rawalpandi" population="909"/>
> >     </Country>
> > 
> > Query to sort by State:
> > Query: for $country in doc("countryinfo.xml")/World/Country/State
> >           order by $country/@name ascending
> >           return $country
> > 
> > OutPut:
> > <?xml version="1.0" encoding="UTF-8"?> <State name="AP" 
> > population="200"/> <State name="Bangalore" 
> population="100"/> <State 
> > name="Delhi" population="600"/> <State name="Islamabad"
> > population="900"/> <State name="Karachi" population="999"/> <State 
> > name="Madras" population="300"/> <State name="Rawalpandi" 
> > population="909"/>
> > 
> > Java Program:
> > import net.sf.saxon.Query;
> > public class SortXMLData {
> >    public static void main(String[] args) {
> >        Query query = new Query();
> >        String arg[] = {"C:/countryinfo.xq"};  // contains query
> >        try{
> > 	query.main(arg);
> >        } catch(Exception ex){
> > 	System.out.println("Exception: "+ex);
> >       }
> >    }
> > }
> > 
> > - Khan
> > --
> > View this message in context: 
> > http://www.nabble.com/sorting-xml-data-in-alphabetical-order-t
> > p19920246p21027601.html
> > Sent from the Xml Beans - Dev mailing list archive at Nabble.com.
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> > For additional commands, e-mail: dev-help@xmlbeans.apache.org
> > 
> > 
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


RE: sorting xml data in alphabetical order

Posted by Radu Preotiuc-Pietro <ra...@oracle.com>.
You could post the XQuery you used and we could try to take a look at it and see what's wrong. Or, in the time that it will take you to debug it, you can learn to use XmlCursor and implement the functionality that way.

Radu 

> -----Original Message-----
> From: Rauf khan [mailto:forum.khan@gmail.com] 
> Sent: Tuesday, December 16, 2008 12:37 AM
> To: dev@xmlbeans.apache.org
> Subject: Re: sorting xml data in alphabetical order
> 
> 
> I was trying with the examples given at
> http://www.yukonxml.com/articles/xquery/ by using saxon8.jar. 
> Iam able to sort only ONE time means i can sort by COUNTRY & 
> not by STATE & vise versa also a part of the xml code will be 
> missed in the output.
> 
> Input XML File: countryinfo.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <World>
>     <Country name="Pakistan">
>         <State name="Karachi" population="999"/>
>         <State name="Islamabad" population="900"/>
>         <State name="Rawalpandi" population="909"/>
>     </Country>
>     <Country name="India">
>         <State name="Bangalore" population="100"/>
>         <State name="AP" population="200"/>
>         <State name="Madras" population="300"/>
>         <State name="Delhi" population="600"/>
>     </Country>
> </World>
> 
> Query to sort by Country:
> Query: for $country in doc("countryinfo.xml")/World/Country
>           order by $country/@name ascending
>           return $country
> 
> OutPut:
> <?xml version="1.0" encoding="UTF-8"?>
> <Country name="India">
>         <State name="Bangalore" population="100"/>
>         <State name="AP" population="200"/>
>         <State name="Madras" population="300"/>
>         <State name="Delhi" population="600"/>
>     </Country>
> <Country name="Pakistan">
>         <State name="Karachi" population="999"/>
>         <State name="Islamabad" population="900"/>
>         <State name="Rawalpandi" population="909"/>
>     </Country>
> 
> Query to sort by State:
> Query: for $country in doc("countryinfo.xml")/World/Country/State
>           order by $country/@name ascending
>           return $country
> 
> OutPut:
> <?xml version="1.0" encoding="UTF-8"?>
> <State name="AP" population="200"/>
> <State name="Bangalore" population="100"/> <State 
> name="Delhi" population="600"/> <State name="Islamabad" 
> population="900"/> <State name="Karachi" population="999"/> 
> <State name="Madras" population="300"/> <State 
> name="Rawalpandi" population="909"/>
> 
> Java Program:
> import net.sf.saxon.Query;
> public class SortXMLData {
>    public static void main(String[] args) {
>        Query query = new Query();
>        String arg[] = {"C:/countryinfo.xq"};  // contains query
>        try{
> 	query.main(arg);
>        } catch(Exception ex){
> 	System.out.println("Exception: "+ex);
>       }
>    }
> }
> 
> - Khan
> --
> View this message in context: 
> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-t
> p19920246p21027601.html
> Sent from the Xml Beans - Dev mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


Re: sorting xml data in alphabetical order

Posted by Rauf khan <fo...@gmail.com>.
I was trying with the examples given at
http://www.yukonxml.com/articles/xquery/ by using saxon8.jar. Iam able to
sort only ONE time means i can sort by COUNTRY & not by STATE & vise versa
also a part of the xml code will be missed in the output.

Input XML File: countryinfo.xml
<?xml version="1.0" encoding="UTF-8"?>
<World>
    <Country name="Pakistan">
        <State name="Karachi" population="999"/>
        <State name="Islamabad" population="900"/>
        <State name="Rawalpandi" population="909"/>
    </Country>
    <Country name="India">
        <State name="Bangalore" population="100"/>
        <State name="AP" population="200"/>
        <State name="Madras" population="300"/>
        <State name="Delhi" population="600"/>
    </Country>
</World>

Query to sort by Country:
Query: for $country in doc("countryinfo.xml")/World/Country 
          order by $country/@name ascending
          return $country

OutPut:
<?xml version="1.0" encoding="UTF-8"?>
<Country name="India">
        <State name="Bangalore" population="100"/>
        <State name="AP" population="200"/>
        <State name="Madras" population="300"/>
        <State name="Delhi" population="600"/>
    </Country>
<Country name="Pakistan">
        <State name="Karachi" population="999"/>
        <State name="Islamabad" population="900"/>
        <State name="Rawalpandi" population="909"/>
    </Country>

Query to sort by State:
Query: for $country in doc("countryinfo.xml")/World/Country/State 
          order by $country/@name ascending
          return $country

OutPut:
<?xml version="1.0" encoding="UTF-8"?>
<State name="AP" population="200"/>
<State name="Bangalore" population="100"/>
<State name="Delhi" population="600"/>
<State name="Islamabad" population="900"/>
<State name="Karachi" population="999"/>
<State name="Madras" population="300"/>
<State name="Rawalpandi" population="909"/>

Java Program:
import net.sf.saxon.Query;
public class SortXMLData {
   public static void main(String[] args) {
       Query query = new Query();
       String arg[] = {"C:/countryinfo.xq"};  // contains query
       try{
	query.main(arg);
       } catch(Exception ex){
	System.out.println("Exception: "+ex);
      }
   }
}

- Khan
-- 
View this message in context: http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp19920246p21027601.html
Sent from the Xml Beans - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


Re: sorting xml data in alphabetical order

Posted by Jacob Danner <ja...@gmail.com>.
Can you post the query you are using?
-jacobd

On Mon, Dec 15, 2008 at 1:50 AM, Rauf khan <fo...@gmail.com> wrote:
>
> I tried by using Saxon Query but couldnt get to the final solution. Can
> anyone please help me out with a java program in getting the expected result
> [sorted xml data].. Please no use of Array/Hashmap type of logic.
>
> UnSorted XML Data
> <?xml version="1.0" encoding="UTF-8"?>
> <World>
>    <Country name="Pakistan">
>        <State name="Karachi" population="999"/>
>        <State name="Islamabad" population="900"/>
>        <State name="Rawalpandi" population="909"/>
>    </Country>
>    <Country name="India">
>        <State name="Bangalore" population="100"/>
>        <State name="AP" population="200"/>
>        <State name="Madras" population="300"/>
>        <State name="Kerala" population="400"/>
>        <State name="Hyderabad" population="500"/>
>        <State name="Delhi" population="600"/>
>    </Country>
> </World>
>
> Expected Result: Sorted XML Data
> <?xml version="1.0" encoding="UTF-8"?>
> <World>
>    <Country name="India">
>        <State name="AP" population="200"/>
>        <State name="Bangalore" population="100"/>
>        <State name="Delhi" population="600"/>
>        <State name="Hyderabad" population="500"/>
>        <State name="Kerala" population="400"/>
>        <State name="Madras" population="300"/>
>    </Country>
>    <Country name="Pakistan">
>        <State name="Islamabad" population="900"/>
>        <State name="Karachi" population="999"/>
>        <State name="Rawalpandi" population="909"/>
>    </Country>
> </World>
>
>
> - Khan
>
>
> Sachin Thatte wrote:
>>
>> Sorting should be possible using the order by clause in Saxon Xquery.
>>
>> -Sachin
>>
>> -----Original Message-----
>> From: Jacob Danner [mailto:jacob.danner@gmail.com]
>> Sent: Friday, October 10, 2008 9:34 AM
>> To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
>> Subject: Re: sorting xml data in alphabetical order
>>
>> Passing on the the user list since this is more of a user question.
>> AFAIK, xmlbeans provides no way to do this internally so you are going to
>> need to manually sort the array before you set the value of country. The
>> JDK provides Arrays.sort, but you can investigate using other sort
>> routines.
>>
>> HTH,
>> -jacobd
>>
>>
>> On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>>  Using the jar of the xsd i was able to create an xml file & read it.
>>> Now can anyone pls let me know how to sort the xml file in
>>> alphabetical order including the parent & its child nodes. My xml file
>>> structure is like this:
>>>
>>> <country name="India>
>>>    <state>Goa</state>
>>>    <state>Rajastan</state>
>>>    <state>Bhopal</state>
>>> </country>
>>> <country name="America">
>>>    <state>Texas</state>
>>>    <state>Washington</state>
>>>    <state>Maryland</state>
>>>    <state>Alaska</state>
>>> </country>
>>>
>>>
>>> Expected Result:
>>> -----------------
>>> <country name="America">
>>>    <state>Alaska</state>
>>>    <state>Maryland</state>
>>>    <state>Texas</state>
>>>    <state>Washington</state>
>>> </country>
>>> <country name="India>
>>>    <state>Bhopal</state>
>>>    <state>Goa</state>
>>>    <state>Rajastan</state>
>>> </country>
>>>
>>>
>>> Thanks in Advance.
>>> Rauf Khan
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp1992024
>>> 6p19920246.html Sent from the Xml Beans - Dev mailing list archive at
>>> Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
>>> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>>
>>
>> Notice:  This email message, together with any attachments, may contain
>> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
>> entities,  that may be confidential,  proprietary,  copyrighted  and/or
>> legally privileged, and is intended solely for the use of the individual
>> or entity named in this message. If you are not the intended recipient,
>> and have received this message in error, please immediately return this by
>> email and then delete it.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp19920246p21010971.html
> Sent from the Xml Beans - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


RE: sorting xml data in alphabetical order

Posted by Rauf khan <fo...@gmail.com>.
I tried by using Saxon Query but couldnt get to the final solution. Can
anyone please help me out with a java program in getting the expected result
[sorted xml data].. Please no use of Array/Hashmap type of logic.

UnSorted XML Data
<?xml version="1.0" encoding="UTF-8"?>
<World>
    <Country name="Pakistan">
        <State name="Karachi" population="999"/>
        <State name="Islamabad" population="900"/>
        <State name="Rawalpandi" population="909"/>
    </Country>
    <Country name="India">
        <State name="Bangalore" population="100"/>
        <State name="AP" population="200"/>
        <State name="Madras" population="300"/>
        <State name="Kerala" population="400"/>
        <State name="Hyderabad" population="500"/>
        <State name="Delhi" population="600"/>
    </Country>
</World>

Expected Result: Sorted XML Data
<?xml version="1.0" encoding="UTF-8"?>
<World>
    <Country name="India">
        <State name="AP" population="200"/>
        <State name="Bangalore" population="100"/>
        <State name="Delhi" population="600"/>
        <State name="Hyderabad" population="500"/>
        <State name="Kerala" population="400"/>
        <State name="Madras" population="300"/>
    </Country>
    <Country name="Pakistan">
        <State name="Islamabad" population="900"/>
        <State name="Karachi" population="999"/>
        <State name="Rawalpandi" population="909"/>
    </Country>
</World>


- Khan


Sachin Thatte wrote:
> 
> Sorting should be possible using the order by clause in Saxon Xquery.
> 
> -Sachin
> 
> -----Original Message-----
> From: Jacob Danner [mailto:jacob.danner@gmail.com] 
> Sent: Friday, October 10, 2008 9:34 AM
> To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
> Subject: Re: sorting xml data in alphabetical order
> 
> Passing on the the user list since this is more of a user question.
> AFAIK, xmlbeans provides no way to do this internally so you are going to
> need to manually sort the array before you set the value of country. The
> JDK provides Arrays.sort, but you can investigate using other sort
> routines.
> 
> HTH,
> -jacobd
> 
> 
> On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
>>
>> Hi,
>>
>>  Using the jar of the xsd i was able to create an xml file & read it. 
>> Now can anyone pls let me know how to sort the xml file in 
>> alphabetical order including the parent & its child nodes. My xml file
>> structure is like this:
>>
>> <country name="India>
>>    <state>Goa</state>
>>    <state>Rajastan</state>
>>    <state>Bhopal</state>
>> </country>
>> <country name="America">
>>    <state>Texas</state>
>>    <state>Washington</state>
>>    <state>Maryland</state>
>>    <state>Alaska</state>
>> </country>
>>
>>
>> Expected Result:
>> -----------------
>> <country name="America">
>>    <state>Alaska</state>
>>    <state>Maryland</state>
>>    <state>Texas</state>
>>    <state>Washington</state>
>> </country>
>> <country name="India>
>>    <state>Bhopal</state>
>>    <state>Goa</state>
>>    <state>Rajastan</state>
>> </country>
>>
>>
>> Thanks in Advance.
>> Rauf Khan
>>
>> --
>> View this message in context: 
>> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp1992024
>> 6p19920246.html Sent from the Xml Beans - Dev mailing list archive at 
>> Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
>> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
> 
> 
> Notice:  This email message, together with any attachments, may contain
> information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
> entities,  that may be confidential,  proprietary,  copyrighted  and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this by
> email and then delete it.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp19920246p21010971.html
Sent from the Xml Beans - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


RE: sorting xml data in alphabetical order

Posted by Sachin Thatte <sa...@oracle.com>.
Sorting should be possible using the order by clause in Saxon Xquery.

-Sachin

-----Original Message-----
From: Jacob Danner [mailto:jacob.danner@gmail.com] 
Sent: Friday, October 10, 2008 9:34 AM
To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
Subject: Re: sorting xml data in alphabetical order

Passing on the the user list since this is more of a user question.
AFAIK, xmlbeans provides no way to do this internally so you are going to need to manually sort the array before you set the value of country. The JDK provides Arrays.sort, but you can investigate using other sort routines.

HTH,
-jacobd


On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
>
> Hi,
>
>  Using the jar of the xsd i was able to create an xml file & read it. 
> Now can anyone pls let me know how to sort the xml file in 
> alphabetical order including the parent & its child nodes. My xml file structure is like this:
>
> <country name="India>
>    <state>Goa</state>
>    <state>Rajastan</state>
>    <state>Bhopal</state>
> </country>
> <country name="America">
>    <state>Texas</state>
>    <state>Washington</state>
>    <state>Maryland</state>
>    <state>Alaska</state>
> </country>
>
>
> Expected Result:
> -----------------
> <country name="America">
>    <state>Alaska</state>
>    <state>Maryland</state>
>    <state>Texas</state>
>    <state>Washington</state>
> </country>
> <country name="India>
>    <state>Bhopal</state>
>    <state>Goa</state>
>    <state>Rajastan</state>
> </country>
>
>
> Thanks in Advance.
> Rauf Khan
>
> --
> View this message in context: 
> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp1992024
> 6p19920246.html Sent from the Xml Beans - Dev mailing list archive at 
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


RE: sorting xml data in alphabetical order

Posted by Sachin Thatte <sa...@oracle.com>.
Sorting should be possible using the order by clause in Saxon Xquery.

-Sachin

-----Original Message-----
From: Jacob Danner [mailto:jacob.danner@gmail.com] 
Sent: Friday, October 10, 2008 9:34 AM
To: dev@xmlbeans.apache.org; user@xmlbeans.apache.org
Subject: Re: sorting xml data in alphabetical order

Passing on the the user list since this is more of a user question.
AFAIK, xmlbeans provides no way to do this internally so you are going to need to manually sort the array before you set the value of country. The JDK provides Arrays.sort, but you can investigate using other sort routines.

HTH,
-jacobd


On Fri, Oct 10, 2008 at 8:11 AM, Rauf khan <fo...@gmail.com> wrote:
>
> Hi,
>
>  Using the jar of the xsd i was able to create an xml file & read it. 
> Now can anyone pls let me know how to sort the xml file in 
> alphabetical order including the parent & its child nodes. My xml file structure is like this:
>
> <country name="India>
>    <state>Goa</state>
>    <state>Rajastan</state>
>    <state>Bhopal</state>
> </country>
> <country name="America">
>    <state>Texas</state>
>    <state>Washington</state>
>    <state>Maryland</state>
>    <state>Alaska</state>
> </country>
>
>
> Expected Result:
> -----------------
> <country name="America">
>    <state>Alaska</state>
>    <state>Maryland</state>
>    <state>Texas</state>
>    <state>Washington</state>
> </country>
> <country name="India>
>    <state>Bhopal</state>
>    <state>Goa</state>
>    <state>Rajastan</state>
> </country>
>
>
> Thanks in Advance.
> Rauf Khan
>
> --
> View this message in context: 
> http://www.nabble.com/sorting-xml-data-in-alphabetical-order-tp1992024
> 6p19920246.html Sent from the Xml Beans - Dev mailing list archive at 
> Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: dev-help@xmlbeans.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org