开发者

How to sort xml files using SAX

I have 6 XML files containing the following tag the first XML file is

<root>
<firstName> Smith</firstName>
<lastname>Joe</lastname>
开发者_运维知识库<Age>60</age>
</root>

the second is

<root>
<firstName> John</firstName>
<lastname>Andrew</lastname>
<Age>55</age>
</root>

and so on

the required is to print the firstname,lastname,age and I have done that in agood way.However, I need also to print ages sorted by age so first should be 55 then 60. I could not do that by sax it was really


IF you use sax parser you should use some intermediate structure and sort it in it (like one of the Collections). Sax parser is event based so you can't sort it really using it.


The only possible reason for using SAX is because you don't want to allocate memory to store the whole document. If you're sorting, then SAX gives you no benefits - you're using a very low-level interface to no purpose. If you want to sort the data then by far the best solution is to use a high-level XML processing language such as XSLT or XQuery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜