tags:

views:

114

answers:

3

Hi

how to to sort an XML file using Qt

my file look like this :

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <task next="2" first="1" name="2" value="name1"/>
    <task next="3" first="1" name="1" value="name2"/>
    <task next="4" first="3" name="4" value="name3"/>
    <task next="4" first="1" name="6" value="name4"/>
    <task next="5" first="2" name="3" value="name5"/>
    <task next="5" first="4" name="5" value="name6"/>
</project>

Thanks.

A: 

What do you mean by sorting an xml file?
I think this needs a bit more thought.

Either sort the values after you read them from the file in your app or to work on the XML file directly You may wish to look into xslt.

Martin Beckett
A: 

Hi,

I want to sort the records by tag "first" like this :

<project> 
    <task next="2" first="1" name="2" value="name1"/> 
    <task next="3" first="1" name="1" value="name2"/>
    <task next="4" first="1" name="6" value="name4"/>
    <task next="5" first="2" name="3" value="name5"/>   
    <task next="4" first="3" name="4" value="name3"/> 
    <task next="5" first="4" name="5" value="name6"/> 
</project> 
Hannibal
You should really edit this into your original question, instead of posting it as an answer.
Jerry Coffin
The meaning with this post?
mslot
Aaaah... Got it :)
mslot
+1  A: 

Basically, you need to parse the XML file into a set of records, sort the records on the appropriate field, then write the result back out as a new XML file. There are zillions of XML parsers out there that are intended to make it easy for you to parse the data. Personally, I've always written my own code to handle it. It's almost as fast to write, and executes quite a bit faster -- but that's me, and the XML I've parsed this was has mostly been fairly simple. If you lack experience at writing parsers and/or don't care as much about execution speed, chances are that using an existing parser will be a better choice.

Jerry Coffin