DOM,SAX和StAX XML解析器之间有什么区别?
我正在使用Apache Tomcat开发RSS供稿聚合器.我想知道使用哪个解析器来读取RSS提要.我应该使用DOM,SAX还是StAX?我知道有一些特定的库可以读取Java的RSS feed,但是由于这是一个大学项目,所以我不建议使用这些库. 谢谢.
I'm developing a RSS feed aggregator with Apache Tomcat. I was wondering which parser to use in order to read RSS feeds. Should I use DOM, SAX or StAX? I know that there are libraries specific to read RSS feeds with java but since this is a university project I am not supposed to use those. Thank you.
这主要取决于您的需求.每个都有自己的功能.
It mostly depends on your needs. Each has it's own features.
DOM -将整个内容拖入内存并在内存中四处走动.适用于您想用来处理复杂事物的较小的XML块. XSLT使用DOM.
DOM - pull the whole thing into memory and walk around inside it. Good for comparatively small chunks of XML that you want to do complex stuff with. XSLT uses DOM.
SAX -在XML到达时走动,观察它们飞过的事物.适用于大量数据或相对简单的处理.
SAX - Walk the XML as it arrives watching for things as they fly past. Good for large amounts of data or comparatively simple processing.
StAX -与SAX相似,但您不对流中发现的事件进行响应,而是通过xml进行迭代-请参见
StAX - Much like SAX but instead of responding to events found in the stream you iterate through the xml - See When should I choose SAX over StAX? for discussion of which is best.
这里有很好的讨论使用Java中的DOM,SAX和StAX解析器解析XML -作者:Mohamed Sanaulla.注意:他的SAX解析器有问题-他应该追加字符,而不是替换字符,因为字符数据是累积的并且可能成块出现.
There's a good discussion here Parsing XML using DOM, SAX and StAX Parser in Java - By Mohamed Sanaulla. NB: There's a fault in his SAX parser - he should append characters, not replace them as character data is cumulative and may arrive in chunks.
content = String.copyValueOf(ch, start, length);
应该是
content += String.copyValueOf(ch, start, length);
还有 Kaan Yamanyar 的博客文章 DOM,SAX或StAX之间的区别.