org.zkoss.idom

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » zk » org.zkoss.idom 
org.zkoss.idom
org.zkoss.idom

The iDOM representation of XML DOM tree.


Author: Tom M. Yeh
Contributors:
Copyright (C) 2001 Potix Corporation. All Rights Reserved.

Overview

It is Potix's DOM representation for XML. The concept is similar to JDOM -- using Java collections and concrete classes. However, we do have many enhancements (many of them are the reasons we don't extend JDOM, but writing a new one). Refer to Port from JDOM to iDOM for more details.

Although iDOM supports W3C/DOM, W3C/DOM's API is generated deprecated unless using them with third part utilities, like Xalan's XPath. The reason is that W3C/DOM API is another complete set of API that is easily confusing with iDOM API. The iDOM API is designed to avoid making any connection between their names. However, some cases are hardly avoided. For example, org.w3c.dom.Element.getAttribute returns an empty string if the attribute not found, while Element.getAttributeValue returns null if the attribute not found.


Usage

Generic Sample

Method 1: Let SAXBuilder create the SAX parser

import org.zkoss.idom.input.SAXBuilder;
import org.zkoss.idom.Document;

SAXBuilder builder = new SAXBuilder(true, false, true);
Document doc = builder.build("file.xml");

Advantages: simple. Caller needs no anything about a SAX parser.

Method 2: Create a parser explicitly

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.zkoss.idom.input.SAXBuilder;
import org.zkoss.idom.Document;

SAXParserFactory factory = SAXParserFactory.newInstance();
...//configure factory as you want
SAXParser parser = factory.newSAXParser();
SAXBuilder builder = new SAXBuilder(parser);
Document doc = builder.build("file.xml");

Advantages: a SAX parser could be used in different palces.

Parsing a XML

for (Iterator it = document.getElements("product").iterator();
it.hasNext();){
  String name = ((Element)it.next()).getElementValue("name", true);
  ...
}

The getElements and getElement methods of Group are powerful to drill down a iDOM tree sequentially.

To select beyond sequence searching (and regular expression), org.zkoss.xml.XPath could be used.


Extension to W3C DOM

  • A new item/node is added, called Binary (Item.BINARY_NODE), to hold any kind of Object (not just String-type).

Notes

  • Adding attributes with namespace might cause the tree to be illegal W3C/DOM. Examples, conflict prefix (same prefix but different URI). We will implement a method to check the consistency, which will be done before output.
  • Every item has zero or one owning document. To be safe, only vertices without any owning document are allowed to be added to other tree. Otherwise, Item.detach or clone must be called explicitly.
  • Some methods in Item look similar to those of Node, but behave differently as follows.
    Item Node
    getText

    Returns the text content.

    getNodeValue

    The same as getText, except Element whose getValue returns always null.


Histroy

September 27, 2001 Tom M. Yeh Project created. The original plan is to be an extension of JDOM.
October 4, 2001 Tom M. Yeh Alpha 1 as an extenstion of JDOM. Tested with JDOM beta 7.
October 22-26, 2001 Tom M. Yeh Alpha 1 of the rewritten version. On October 21, decide to rewrite to be independent of JDOM.
November 3-4, 2001 Tom M. Yeh Alpha 2.
  • SAXBuilder is enhance to support more options like DocumentBuilderFactory.
  • All un-expanding entities are put under EntityReference (if isExpandEntityReferences is true).
January 7-8, 2002 Tom M. Yeh Alpha 3.
  • The modification flag is introduced.
  • The content concept is introduced.
Java Source File NameTypeComment
Attributable.javaInterface Represents a class that has attributes.
Attribute.javaClass The iDOM attribute.

Design decision: Attribute is also a item.

Binable.javaInterface Represent a class that allows any type of objects, not just String.
Binary.javaClass The binary item.
CData.javaClass The iDOM CDATA.
Comment.javaClass The iDOM Comment.
DocType.javaClass The iDOM DocType.
Document.javaClass Represents Document which is also W3C/DOM's document, ie, org.w3c.dom.Document.
DOMException.javaClass Denotes an operation is not supported.
Element.javaClass The iDOM element.
EntityReference.javaClass The iDOM entity reference.
Group.javaInterface Represents an item might have children.
Item.javaInterface Represents an item (aka., node) of a iDOM tree.
Namespace.javaClass Represents the namespace.
Namespaceable.javaInterface Represents a class that supports namespace.
ProcessingInstruction.javaClass The iDOM processing instruction.
Text.javaClass The iDOM Text.
Textual.javaInterface Represents an object that is mainly for storing "text". It is usually implemented by a class that also implements Item.

A "text" is usually a string (e.g., Text, Comment and CDATA) but could be any object (e.g., Binary).

The getText method of some parent, e.g., Element, catenates the text of its children if they implement this interface and Textual.isPartOfParentText returns true.

Note: the class that implement this interface must have a constructor with a single argument whose type is String.

Verifier.javaClass The verifier to verify W3C/DOM related constraints.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.