package.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <html>
  2. <body>
  3. <p>
  4. This is a Free Software DOM Level 3 implementation, supporting these features:
  5. <ul>
  6. <li>"XML"</li>
  7. <li>"Events"</li>
  8. <li>"MutationEvents"</li>
  9. <li>"HTMLEvents" (won't generate them though)</li>
  10. <li>"UIEvents" (also won't generate them)</li>
  11. <li>"USER-Events" (a conformant extension)</li>
  12. <li>"Traversal" (optional)</li>
  13. <li>"XPath"</li>
  14. <li>"LS" and "LS-Async"</li>
  15. </ul>
  16. It is intended to be a reasonable base both for
  17. experimentation and supporting additional DOM modules as clean layers.
  18. </p>
  19. <p>
  20. Note that while DOM does not specify its behavior in the
  21. face of concurrent access, this implementation does.
  22. Specifically:
  23. <ul>
  24. <li>If only one thread at a time accesses a Document,
  25. of if several threads cooperate for read-only access,
  26. then no concurrency conflicts will occur.</li>
  27. <li>If several threads mutate a given document
  28. (or send events using it) at the same time,
  29. there is currently no guarantee that
  30. they won't interfere with each other.</li>
  31. </ul>
  32. </p>
  33. <h3>Design Goals</h3>
  34. <p>
  35. A number of DOM implementations are available in Java, including
  36. commercial ones from Sun, IBM, Oracle, and DataChannel as well as
  37. noncommercial ones from Docuverse, OpenXML, and Silfide. Why have
  38. another? Some of the goals of this version:
  39. </p>
  40. <ul>
  41. <li>Advanced DOM support. This was the first generally available
  42. implementation of DOM Level 2 in Java, and one of the first Level 3
  43. and XPath implementations.</li>
  44. <li> Free Software. This one is distributed under the GPL (with
  45. "library exception") so it can be used with a different class of
  46. application.</li>
  47. <li>Second implementation syndrome. I can do it simpler this time
  48. around ... and heck, writing it only takes a bit over a day once you
  49. know your way around.</li>
  50. <li>Sanity check the then-current Last Call DOM draft. Best to find
  51. bugs early, when they're relatively fixable. Yes, bugs were found.</li>
  52. <li>Modularity. Most of the implementations mentioned above are part
  53. of huge packages; take all (including bugs, of which some have far
  54. too many), or take nothing. I prefer a menu approach, when possible.
  55. This code is standalone, not beholden to any particular parser or XSL
  56. or XPath code.</li>
  57. <li>OK, I'm a hacker, I like to write code.</li>
  58. </ul>
  59. <p>
  60. This also works with the GNU Compiler for Java (GCJ). GCJ promises
  61. to be quite the environment for programming Java, both directly and from
  62. C++ using the new CNI interfaces (which really use C++, unlike JNI). </p>
  63. <h3>Open Issues</h3>
  64. <p>At this writing:</p>
  65. <ul>
  66. <li>See below for some restrictions on the mutation event
  67. support ... some events aren't reported (and likely won't be).</li>
  68. <li>More testing and conformance work is needed.</li>
  69. <li>We need an XML Schema validator (actually we need validation in the DOM
  70. full stop).</li>
  71. </ul>
  72. <p>
  73. I ran a profiler a few times and remove some of the performance hotspots,
  74. but it's not tuned. Reporting mutation events, in particular, is
  75. rather costly -- it started at about a 40% penalty for appendNode calls,
  76. I've got it down around 12%, but it'll be hard to shrink it much further.
  77. The overall code size is relatively small, though you may want to be rid of
  78. many of the unused DOM interface classes (HTML, CSS, and so on).
  79. </p>
  80. <h2><a name="features">Features of this Package</a></h2>
  81. <p> Starting with DOM Level 2, you can really see that DOM is constructed
  82. as a bunch of optional modules around a core of either XML or HTML
  83. functionality. Different implementations will support different optional
  84. modules. This implementation provides a set of features that should be
  85. useful if you're not depending on the HTML functionality (lots of convenience
  86. functions that mostly don't buy much except API surface area) and user
  87. interface support. That is, browsers will want more -- but what they
  88. need should be cleanly layered over what's already here. </p>
  89. <h3> Core Feature Set: "XML" </h3>
  90. <p> This DOM implementation supports the "XML" feature set, which basically
  91. gets you four things over the bare core (which you're officially not supposed
  92. to implement except in conjunction with the "XML" or "HTML" feature). In
  93. order of decreasing utility, those four things are: </p> <ol>
  94. <li> ProcessingInstruction nodes. These are probably the most
  95. valuable thing. Handy little buggers, in part because all the APIs
  96. you need to use them are provided, and they're designed to let you
  97. escape XML document structure rules in controlled ways.</li>
  98. <li> CDATASection nodes. These are of of limited utility since CDATA
  99. is just text that prints funny. These are of use to some sorts of
  100. applications, though I encourage folk to not use them. </li>
  101. <li> DocumentType nodes, and associated Notation and Entity nodes.
  102. These appear to be useless. Briefly, these "Type" nodes expose no
  103. typing information. They're only really usable to expose some lexical
  104. structure that almost every application needs to ignore. (XML editors
  105. might like to see them, but they need true typing information much more.)
  106. I strongly encourage people not to use these. </li>
  107. <li> EntityReference nodes can show up. These are actively annoying,
  108. since they add an extra level of hierarchy, are the cause of most of
  109. the complexity in attribute values, and their contents are immutable.
  110. Avoid these.</li>
  111. </ol>
  112. <h3> Optional Feature Sets: "Events", and friends </h3>
  113. <p> Events may be one of the more interesting new features in Level 2.
  114. This package provides the core feature set and exposes mutation events.
  115. No gooey events though; if you want that, write a layered implementation! </p>
  116. <p> Three mutation events aren't currently generated:</p> <ul>
  117. <li> <em>DOMSubtreeModified</em> is poorly specified. Think of this
  118. as generating one such event around the time of finalization, which
  119. is a fully conformant implementation. This implementation is exactly
  120. as useful as that one. </li>
  121. <li> <em>DOMNodeRemovedFromDocument</em> and
  122. <em>DOMNodeInsertedIntoDocument</em> are supposed to get sent to
  123. every node in a subtree that gets removed or inserted (respectively).
  124. This can be <em>extremely costly</em>, and the removal and insertion
  125. processing is already significantly slower due to event reporting.
  126. It's much easier, and more efficient, to have a listener higher in the
  127. tree watch removal and insertion events through the bubbling or capture
  128. mechanisms, than it is to watch for these two events.</li>
  129. </ul>
  130. <p> In addition, certain kinds of attribute modification aren't reported.
  131. A fix is known, but it couldn't report the previous value of the attribute.
  132. More work could fix all of this (as well as reduce the generally high cost
  133. of childful attributes), but that's not been done yet. </p>
  134. <p> Also, note that it is a <em>Bad Thing&#153;</em> to have the listener
  135. for a mutation event change the ancestry for the target of that event.
  136. Or to prevent mutation events from bubbling to where they're needed.
  137. Just don't do those, OK? </p>
  138. <p> As an experimental feature (named "USER-Events"), you can provide
  139. your own "user" events. Just name them anything starting with "USER-"
  140. and you're set. Dispatch them through, bubbling, capturing, or what
  141. ever takes your fancy. One important thing you can't currently do is
  142. pass any data (like an object) with those events. Maybe later there
  143. will be a "UserEvent" interface letting you get some substantial use
  144. out of this mechanism even if you're not "inside" of a DOM package.</p>
  145. <p> You can create and send HTML events. Ditto UIEvents. Since DOM
  146. doesn't require a UI, it's the UI's job to send them; perhaps that's
  147. part of your application. </p>
  148. <p><em>This package may be built without the ability to report mutation
  149. events, gaining a significant speedup in DOM construction time. However,
  150. if that is done then certain other features -- notably node iterators
  151. and getElementsByTagname -- will not be available.</em>
  152. <h3> Optional Feature: "Traversal" </h3>
  153. <p> Each DOM node has all you need to walk to everything connected
  154. to that node. Lightweight, efficient utilities are easily layered on
  155. top of just the core APIs. </p>
  156. <p> Traversal APIs are an optional part of DOM Level 2, providing
  157. a not-so-lightweight way to walk over DOM trees, if your application
  158. didn't already have such utilities for use with data represented via
  159. DOM. Implementing this helped debug the (optional) event and mutation
  160. event subsystems, so it's provided here. </p>
  161. <p> At this writing, the "TreeWalker" interface isn't implemented. </p>
  162. <h2><a name='avoid'>DOM Functionality to Avoid</a></h2>
  163. <p> For what appear to be a combination of historical and "committee
  164. logic" reasons, DOM has a number of <em>features which I strongly advise
  165. you to avoid using</em> in your library and application code. These
  166. include the following types of DOM nodes; see the documentation for the
  167. implementation class for more information: <ul>
  168. <li> CDATASection
  169. (<a href='DomCDATA.html'>DomCDATA</a> class)
  170. ... use normal Text nodes instead, so you don't have to make
  171. every algorithm recognize multiple types of character data
  172. <li> DocumentType
  173. (<a href='DomDoctype.html'>DomDocType</a> class)
  174. ... if this held actual typing information, it might be useful
  175. <li> Entity
  176. (<a href='DomEntity.html'>DomEntity</a> class)
  177. ... neither parsed nor unparsed entities work well in DOM; it
  178. won't even tell you which attributes identify unparsed entities
  179. <li> EntityReference
  180. (<a href='DomEntityReference.html'>DomEntityReference</a> class)
  181. ... permitted implementation variances are extreme, all children
  182. are readonly, and these can interact poorly with namespaces
  183. <li> Notation
  184. (<a href='DomNotation.html'>DomNotation</a> class)
  185. ... only really usable with unparsed entities (which aren't well
  186. supported; see above) or perhaps with PIs after the DTD, not with
  187. NOTATION attributes
  188. </ul>
  189. <p> If you really need to use unparsed entities or notations, use SAX;
  190. it offers better support for all DTD-related functionality.
  191. It also exposes actual
  192. document typing information (such as element content models).</p>
  193. <p> Also, when accessing attribute values, use methods that provide their
  194. values as single strings, rather than those which expose value substructure
  195. (Text and EntityReference nodes). (See the <a href='DomAttr.html'>DomAttr</a>
  196. documentation for more information.) </p>
  197. <p> Note that many of these features were provided as partial support for
  198. editor functionality (including the incomplete DTD access). Full editor
  199. functionality requires access to potentially malformed lexical structure,
  200. at the level of unparsed tokens and below. Access at such levels is so
  201. complex that using it in non-editor applications sacrifices all the
  202. benefits of XML; editor aplications need extremely specialized APIs. </p>
  203. <p> (This isn't a slam against DTDs, note; only against the broken support
  204. for them in DOM. Even despite inclusion of some dubious SGML legacy features
  205. such as notations and unparsed entities,
  206. and the ongoing proliferation of alternative schema and validation tools,
  207. DTDs are still the most widely adopted tool
  208. to constrain XML document structure.
  209. Alternative schemes generally focus on data transfer style
  210. applications; open document architectures comparable to
  211. DocBook 4.0 don't yet exist in the schema world.
  212. Feel free to use DTDs; just don't expect DOM to help you.) </p>
  213. </body>
  214. </html>