README.jaxp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. This file describes the jaxp (xml processing) implementation of GNU Classpath.
  2. GNU Classpath includes interfaces and implementations for basic XML processing
  3. in in the java programming language, some general purpose SAX2 utilities, and
  4. transformation.
  5. These classes used to be maintained as part of an external project GNU JAXP
  6. but are now integrated with the rest of the core class library provided by
  7. GNU Classpath.
  8. PACKAGES
  9. . javax.xml.* ... JAXP 1.3 interfaces
  10. . gnu.xml.aelfred2.* ... SAX2 parser + validator
  11. . gnu.xml.dom.* ... DOM Level 3 Core, Traversal, XPath implementation
  12. . gnu.xml.dom.ls.* ... DOM Level 3 Load & Save implementation
  13. . gnu.xml.xpath.* ... JAXP XPath implementation
  14. . gnu.xml.transform.* ... JAXP XSL transformer implementation
  15. . gnu.xml.pipeline.* ... SAX2 event pipeline support
  16. . gnu.xml.stream.* ... StAX pull parser and SAX-over-StAX driver
  17. . gnu.xml.util.* ... various XML utility classes
  18. . gnu.xml.libxmlj.dom.* ... libxmlj DOM Level 3 Core and XPath
  19. . gnu.xml.libxmlj.sax.* ... libxmlj SAX parser
  20. . gnu.xml.libxmlj.transform.* ... libxmlj XSL transformer
  21. . gnu.xml.libxmlj.util.* ... libxmlj utility classes
  22. In the external directory you can find the following packages.
  23. They are not maintained as part of GNU Classpath, but are used by the
  24. classes in the above packages.
  25. . org.xml.sax.* ... SAX2 interfaces
  26. . org.w3c.dom.* ... DOM Level 3 interfaces
  27. . org.relaxng.datatype.* ... RELAX NG pluggable datatypes API
  28. CONFORMANCE
  29. The primary test resources are at http://xmlconf.sourceforge.net
  30. and include:
  31. SAX2/XML conformance tests
  32. That the "xml.testing.Driver" addresses the core XML 1.0
  33. specification requirements, which closely correspond to the
  34. functionality SAX1 provides. The driver uses SAX2 APIs to
  35. test that functionality It is used with a bugfixed version of
  36. the NIST/OASIS XML conformance test cases.
  37. The AElfred2 parser is highly conformant, though it still takes
  38. a few implementation shortcuts. See its package documentation
  39. for information about known XML conformance issues in AElfred2.
  40. The primary issue is using Unicode character tables, rather than
  41. those in the XML specification, for determining what names are
  42. valid. Most applications won't notice the difference, and this
  43. solution is smaller and faster than the alternative.
  44. For validation, a secondary issue is that issues relating to
  45. entity modularity are not validated; they can't all be cleanly
  46. layered. For example, validity constraints related to standalone
  47. declarations and PE nesting are not checked.
  48. The current implementation has also been tested against Elliotte
  49. Rusty Harold's SAXTest test suite (http://www.cafeconleche.org/SAXTest)
  50. and achieves approximately 93% conformance to the SAX specification
  51. according to these tests, higher than any other current Java parser.
  52. SAX2
  53. SAX2 API conformance currently has a minimal JUNIT (0.2) test suite,
  54. which can be accessed at the xmlconf site listed above. It does
  55. not cover namespaces or LexicalHandler and Declhandler extensions
  56. anywhere as exhaustively as the SAX1 level functionality is
  57. tested by the "xml.testing.Driver". However:
  58. - Applying the DOM unit tests to this implementation gives
  59. the LexicalHandler (comments, and boundaries of DTDs,
  60. CDATA sections, and general entities) a workout, and
  61. does the same for DeclHandler entity declarations.
  62. - The pipeline package's layered validator demands that
  63. element and attribute declarations are reported correctly.
  64. By those metrics, SAX2 conformance for AElfred2 is also strong.
  65. DOM Level 3 Core Tests
  66. The DOM implementation has been tested against the W3C DOM Level 3
  67. Core conformance test suite (http://www.w3.org/DOM/Test/). Current
  68. conformance according to these tests is 72.3%. Many of the test
  69. failures are due to the fact that GNU JAXP does not currently
  70. provide any W3C XML Schema support.
  71. XSL transformation
  72. The transformer and XPath implementation have been tested against
  73. the OASIS XSLT and XPath TC test suite. Conformance against the
  74. Xalan tests is currently 77%.
  75. libxmlj
  76. ========================================================================
  77. libxmlj is an effort to create a 100% JAXP-compatible Java wrapper for
  78. libxml2 and libxslt. JAXP is the Java API for XML processing, libxml2
  79. is the XML C library for Gnome, and libxslt is the XSLT C library for
  80. Gnome.
  81. libxmlj currently supports most of the DOM Level 3 Core, Traversal, and
  82. XPath APIs, SAX2, and XSLT transformations. There is no W3C XML Schema
  83. support yet.
  84. libxmlj can parse and transform XML documents extremely quickly in
  85. comparison to Java-based JAXP implementations. DOM manipulations, however,
  86. involve JNI overhead, so the speed of DOM tree construction and traversal
  87. can be slower than the Java implementation.
  88. libxmlj is highly experimental, doesn't always conform to the DOM
  89. specification correctly, and may leak memory. Production use is not advised.
  90. The implementation can be found in gnu/xml/libxmlj and native/jni/xmlj.
  91. See the INSTALL file for the required versions of libxml2 and libxslt.
  92. configure --enable-xmlj will build it.
  93. Usage
  94. ------------------------------------------------------------------------
  95. To enable the various GNU JAXP factories, set the following system properties
  96. (command-line version shown, but they can equally be set programmatically):
  97. AElfred2:
  98. -Djavax.xml.parsers.SAXParserFactory=gnu.xml.aelfred2.JAXPFactory
  99. GNU DOM (using DOM Level 3 Load & Save):
  100. -Djavax.xml.parsers.DocumentBuilderFactory=gnu.xml.dom.DomDocumentBuilderFactory
  101. GNU DOM (using AElfred-only pipeline classes):
  102. -Djavax.xml.parsers.DocumentBuilderFactory=gnu.xml.dom.JAXPFactory
  103. GNU XSL transformer:
  104. -Djavax.xml.transform.TransformerFactory=gnu.xml.transform.TransformerFactoryImpl
  105. GNU StAX:
  106. -Djavax.xml.stream.XMLEventFactory=gnu.xml.stream.XMLEventFactoryImpl
  107. -Djavax.xml.stream.XMLInputFactory=gnu.xml.stream.XMLInputFactoryImpl
  108. -Djavax.xml.stream.XMLOutputFactory=gnu.xml.stream.XMLOutputFactoryImpl
  109. GNU SAX-over-StAX:
  110. -Djavax.xml.parsers.SAXParserFactory=gnu.xml.stream.SAXParserFactory
  111. libxmlj SAX:
  112. -Djavax.xml.parsers.SAXParserFactory=gnu.xml.libxmlj.sax.GnomeSAXParserFactory
  113. libxmlj DOM:
  114. -Djavax.xml.parsers.DocumentBuilderFactory=gnu.xml.libxmlj.dom.GnomeDocumentBuilderFactory
  115. libxmlj XSL transformer:
  116. -Djavax.xml.transform.TransformerFactory=gnu.xml.libxmlj.transform.GnomeTransformerFactory
  117. When using libxmlj, the libxmlj shared library must be available.
  118. In general it is picked up by the runtime using GNU Classpath. If not you
  119. might want to try adding the directory where libxmlj.so is installed
  120. (by default ${prefix}/lib/classpath/) with ldconfig or specifying in the
  121. LD_LIBRARY_PATH environment variable. Additionally, you may need to specify
  122. the location of your shared libraries to the runtime environment using the
  123. java.library.path system property.
  124. Missing (libxmlj) Features
  125. ------------------------------------------------------------------------
  126. See BUGS in native/jni/xmlj for known bugs in the libxmlj native bindings.
  127. This implementation should be thread-safe, but currently all
  128. transformation requests are queued via Java synchronization, which
  129. means that it effectively performs single-threaded. Long story short,
  130. both libxml2 and libxslt are not fully reentrant.
  131. Update: it may be possible to make libxmlj thread-safe nonetheless
  132. using thread context variables.
  133. Update: thread context variables have been introduced. This is very
  134. untested though, libxmlj therefore still has the single thread
  135. bottleneck.
  136. Validation
  137. ===================================================
  138. Pluggable datatypes
  139. ---------------------------------------------------
  140. Validators should use the RELAX NG pluggable datatypes API to retrieve
  141. datatype (XML Schema simple type) implementations in a schema-neutral
  142. fashion. The following code demonstrates looking up a W3C XML Schema
  143. nonNegativeInteger datatype:
  144. DatatypeLibrary xsd = DatatypeLibraryLoader
  145. .createDatatypeLibrary(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  146. Datatype nonNegativeInteger = xsd.createDatatype("nonNegativeInteger");
  147. It is also possible to create new types by derivation. For instance,
  148. to create a datatype that will match a US ZIP code:
  149. DatatypeBuilder b = xsd.createDatatypeBuilder("string");
  150. b.addParameter("pattern", "(^[0-9]{5}$)|(^[0-9]{5}-[0-9]{4}$)");
  151. Datatype zipCode = b.createDatatype();
  152. A datatype library implementation for XML Schema is provided; other
  153. library implementations may be added.