牛仔褲的夏天

          JAVA是藍色的- online

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            30 隨筆 :: 5 文章 :: 15 評論 :: 0 Trackbacks
          <2006年2月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627281234
          567891011

          公告

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          文章檔案

          連接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          When to use DOM

          If your XML documents contain document data (e.g., Framemaker documents stored in XML format), then DOM is a completely natural fit for your solution. If you are creating some sort of document information management system, then you will probably have to deal with a lot of document data. An example of this is the Datachannel RIO product, which can index and organize information that comes from all kinds of document sources (like Word and Excel files). In this case, DOM is well suited to allow programs access to information stored in these documents.

          However, if you are dealing mostly with structured data (the equivalent of serialized Java objects in XML) DOM is not the best choice. That is when SAX might be a better fit.

          When to use SAX

          If the information stored in your XML documents is machine readable (and generated) data then SAX is the right API for giving your programs access to this information. Machine readable and generated data include things like:

          • Java object properties stored in XML format
          • queries that are formulated using some kind of text based query language (SQL, XQL, OQL)
          • result sets that are generated based on queries (this might include data in relational database tables encoded into XML).

          So machine generated data is information that you normally have to create data structures and classes for in Java. A simple example is the address book which contains information about persons, as shown in Figure 1. This address book XML file is not like a word processor document, rather it is a document that contains pure data, which has been encoded into text using XML.

          When your data is of this kind, you have to create your own data structures and classes (object models) anyway in order to manage, manipulate and persist this data. SAX allows you to quickly create a handler class which can create instances of your object models based on the data stored in your XML documents. An example is a SAX document handler that reads an XML document that contains my address book and creates an AddressBook class that can be used to access this information. The first SAX tutorial shows you how to do this. The address book XML document contains person elements, which contain name and email elements. My AddressBook object model contains the following classes:

          • AddressBook class, which is a container for Person objects
          • Person class, which is a container for name and email String objects.

          So my "SAX address book document handler" is responsible for turning person elements into Person objects, and then storing them all in an AddressBook object. This document handler turns the name and email elements into String objects.

          Conclusion

          The SAX document handler you write does element to object mapping. If your information is structured in a way that makes it easy to create this mapping you should use the SAX API. On the other hand, if your data is much better represented as a tree then you should use DOM.

          posted on 2006-02-22 21:52 luckyrobbie 閱讀(204) 評論(0)  編輯  收藏 所屬分類: XML

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 华容县| 内黄县| 密云县| 龙门县| 肇州县| 武功县| 雷波县| 化德县| 新郑市| 朔州市| 虞城县| 东兰县| 犍为县| 壤塘县| 延川县| 杂多县| 格尔木市| 巩留县| 彰武县| 武乡县| 皮山县| 万山特区| 泸定县| 遂川县| 木里| 永寿县| 松原市| 昆山市| 贡觉县| 天等县| 汾阳市| 罗定市| 故城县| 安丘市| 张家川| 苏尼特右旗| 张掖市| 闻喜县| 瑞安市| 兴国县| 宁远县|