[英]DOM vs SAX Java
I have a big xml file that could be downloaded from the internet. 我有一个大的xml文件,可以从互联网上下载。 To parse it I tried using the DOM parser however it doesn't let me skip certain tags as it gives me an error.
为了解析它,我尝试使用DOM解析器但是它不允许我跳过某些标记,因为它给了我一个错误。 Is there a way around this?
有没有解决的办法? If i understood correctly the SAX parser allows you to skip tags whilst the DOM doesn't.
如果我理解正确,SAX解析器允许您跳过标签,而DOM则不允许。 Can someone kindly clarify this fact, as if that is the case, I can't understand what is the advantage of a DOM parser.
有人可以澄清这个事实,好像就是这样,我无法理解DOM解析器的优点是什么。 Thanks in advance.
提前致谢。
DOM was designed as a language-independent object model to hold any XML data, and as such is a large and complex system. DOM被设计为一种独立于语言的对象模型,用于存放任何XML数据,因此是一个庞大而复杂的系统。 It suits well the two-phase approach of first loading an XML document in, then performing various operations on it.
它非常适合首先加载XML文档,然后对其执行各种操作的两阶段方法。 SAX, on the other hand, was designed as a fairly light-weight system using a single-phase approach.
另一方面,SAX被设计为使用单相方法的相当轻量级的系统。 With SAX, user-specified operations are performed as the document is loaded.
使用SAX,在加载文档时执行用户指定的操作。 Some applications use SAX to generate a smaller object model, with uninteresting information filtered out, which is then processed similarly to DOM.
一些应用程序使用SAX生成较小的对象模型,过滤掉不感兴趣的信息,然后以类似于DOM的方式处理。 Note that although DOM and SAX are the well-known "standard" XML APIs, there are plenty of others available, and sometimes a particular application may be better off using a non-standard API.
请注意,尽管DOM和SAX是众所周知的“标准”XML API,但还有很多其他可用的API,有时使用非标准API可能会使特定应用程序更好。 With XML the important bit is always the data;
使用XML,重要的一点始终是数据; code can be rewritten.
代码可以重写。
Some quick points: 一些快速点:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.