Document Object Model

When to Use DOM

On the other hand, if you are dealing with simple data structures and if XML Schema isn't a big part of your plans, then you may find that one of the more object-oriented standards, such as JDOM and dom4j, is better suited for your purpose.

 Because it was designed for use with languages such as C and Perl, DOM does not take advantage of Java's object-oriented features.
看到這裏,也許DOM和我想象的那種不同,到底DOM是怎麼設計爲C,Perl適用的語言的呢?JDom可能就是我以前接觸的那個。在看完了全部內容後,我有了大概的概念。JDom之類專門用來處理比較簡單的文檔,也就是在element之間的內容不是複雜的文檔,或者從dom的角度來講,element中間夾的只是一個text node。而dom就不相同了,他可以處理很複雜的文檔,而且dom的健壯性和執行效率都要遠遠高於jdom。引用原文的一些內容,詳細的講解了如何去選擇dom還是jdom。

As you can see, when you are using DOM, even a simple operation such as getting the text from a node can take a bit of programming. So if your programs handle simple data structures, then JDOM, dom4j, or even the 1.4 regular-expression package (java.util.regex) may be more appropriate for your needs.

For full-fledged documents and complex applications, on the other hand, DOM gives you a lot of flexibility. And if you need to use XML Schema, then again DOM is the way to go--for now, at least.

If you process both documents and data in the applications you develop, then DOM may still be your best choice. After all, after you have written the code to examine and process a DOM structure, it is fairly easy to customize it for a specific purpose. So choosing to do everything in DOM means that you'll only have to deal with one set of APIs, rather than two.

In addition, the DOM standard is a codified standard for an in-memory document model. It's powerful and robust, and it has many implementations. That is a significant decision-making factor for many large installations, particularly for large-scale applications that need to minimize costs resulting from API changes.

Finally, even though the text in an address book may not permit bold, italics, colors, and font sizes today, someday you may want to handle these things. Because DOM will handle virtually anything you throw at it, choosing DOM makes it easier to future proof your application.

 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章