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-pie...@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.k...@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-unsubscr...@xmlbeans.apache.org > > For additional commands, e-mail: dev-h...@xmlbeans.apache.org > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org > For additional commands, e-mail: dev-h...@xmlbeans.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org For additional commands, e-mail: dev-h...@xmlbeans.apache.org