28.04.2015 Views

JSR 206 Java API for XML Processing (JAXP) 1.3 - Oracle Software ...

JSR 206 Java API for XML Processing (JAXP) 1.3 - Oracle Software ...

JSR 206 Java API for XML Processing (JAXP) 1.3 - Oracle Software ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong><br />

Jeff Suttor <br />

Norman Walsh <br />

Kohsuke Kawaguchi


Community Draft<br />

Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong><br />

by Jeff Suttor, Norman Walsh, and Kohsuke Kawaguchi<br />

Copyright ' 2003 Sun Microsystems, Inc.<br />

Public Draft <strong>for</strong> Public Review<br />

The <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Expert Group would like to thank participants in the <strong>Java</strong><br />

Community that are reviewing this <strong>Java</strong> Specification Request. All comments, feedback and guidance from the <strong>Java</strong><br />

Community is appreciated.<br />

A list of open issues follows in the next section. In addition, a dynamic list of open issues and electronic artifacts is<br />

being maintained at <strong>JSR</strong><strong>206</strong>-Public.Dev.<strong>Java</strong>.Net [http://jsr<strong>206</strong>-public.dev.java.net/] under File sharing<br />

[https://jsr<strong>206</strong>-public.dev.java.net/servlets/ProjectDocumentList] in Project tools.<br />

Please submit comments to .<br />

<strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) Specification ("Specification") Version: <strong>1.3</strong> Public<br />

Draft 1.0.0 Status: pre-FCS, Release: December 16, 2003<br />

Copyright 2003 Sun Microsystems, Inc.<br />

4150 Network Circle, Santa Clara, Cali<strong>for</strong>nia 95054, U.S.A.<br />

All rights reserved.<br />

NOTICE<br />

The Specification is protected by copyright and the in<strong>for</strong>mation described therein may be protected by one or more U.S. patents, <strong>for</strong>eign patents,<br />

or pending applications. Except as provided under the following license, no part of the Specification may be reproduced in any <strong>for</strong>m by any means<br />

without the prior written authorization of Sun Microsystems, Inc. ("Sun") and its licensors, if any. Any use of the Specification and the in<strong>for</strong>mation<br />

described therein will be governed by the terms and conditions of this Agreement.<br />

Subject to the terms and conditions of this license, Sun hereby grants you a fully-paid, non-exclusive, non-transferable, limited license (without the<br />

right to sublicense) under Sun’s intellectual property rights to review the Specification only <strong>for</strong> the purposes of evaluation. This license includes<br />

the right to discuss the Specification (including the right to provide limited excerpts of text to the extent relevant to the point[s] under discussion)<br />

with other licensees (under this or a substantially similar version of this Agreement) of the Specification. Other than this limited license, you acquire<br />

no right, title or interest in or to the Specification or any other Sun intellectual property, and the Specification may only be used in accordance with<br />

the license terms set <strong>for</strong>th herein. This license will expire on the earlier of: (i) two (2) years from the date of Release listed above; (ii) the date on<br />

which the final version of the Specification is publicly released; or (iii) the date on which the <strong>Java</strong> Specification Request (<strong>JSR</strong>) to which the Spe<br />

cification corresponds is withdrawn. In addition, this license will terminate immediately without notice from Sun if you fail to comply with any<br />

provision of this license. Upon termination, you must cease use of or destroy the Specification.<br />

TRADEMARKS<br />

No right, title, or interest in or to any trademarks, service marks, or trade names of Sun or Sun’s licensors is granted hereunder. Sun, Sun Microsystems,<br />

the Sun Microsystems logo, <strong>Java</strong>, and the <strong>Java</strong> Coffee Cup logo are trademarks or registered trademarks of the Sun Microsystems, Inc. in the U.S.<br />

and other countries.<br />

DISCLAIMER OF WARRANTIES<br />

THE SPECIFICATION IS PROVIDED "AS IS" AND IS EXPERIMENTAL AND MAY CONTAIN DEFECTS OR DEFICIENCIES WHICH<br />

CANNOT OR WILL NOT BE CORRECTED BY SUN. SUN MAKES NO REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS OR<br />

IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,<br />

OR NON-INFRINGEMENT THAT THE CONTENTS OF THE SPECIFICATION ARE SUITABLE FOR ANY PURPOSE OR THAT ANY<br />

PRACTICE OR IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADE<br />

SECRETS OR OTHER RIGHTS. This document does not represent any commitment to release or implement any portion of the Specification in<br />

any product.<br />

THE SPECIFICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE PERIODICALLY<br />

ADDED TO THE INFORMATION THEREIN; THESE CHANGES WILL BE INCORPORATED INTO NEW VERSIONS OF THE SPECIFIC<br />

ATION, IF ANY. SUN MAY MAKE IMPROVEMENTS AND/OR CHANGES TO THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED


Community Draft<br />

Community Draft<br />

IN THE SPECIFICATION AT ANY TIME. Any use of such changes in the Specification will be governed by the then-current license <strong>for</strong> the ap<br />

plicable version of the Specification.<br />

LIMITATION OF LIABILITY<br />

TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES, IN<br />

CLUDING WITHOUT LIMITATION, LOST REVENUE, PROFITS OR DATA, OR FOR SPECIAL, INDIRECT, CONSEQUENTIAL, INCID<br />

ENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF OR<br />

RELATED TO ANY FURNISHING, PRACTICING, MODIFYING OR ANY USE OF THE SPECIFICATION, EVEN IF SUN AND/OR ITS<br />

LICENSORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.<br />

You will hold Sun (and its licensors) harmless from any claims based on your use of the Specification <strong>for</strong> any purposes other than the limited right<br />

of evaluation as described above, and from any claims that later versions or releases of any Specification furnished to you are incompatible with<br />

the Specification provided to you under this license.<br />

RESTRICTED RIGHTS LEGEND<br />

If this <strong>Software</strong> is being acquired by or on behalf of the U.S. Government or by a U.S. Government prime contractor or subcontractor (at any tier),<br />

then the Government’s rights in the Specification and accompanying documentation shall be only as set <strong>for</strong>th in this license; this is in accordance<br />

with 48 C.F.R. 227.7201 through 227.7202-4 (<strong>for</strong> Department of Defense (DoD) acquisitions) and with 48 C.F.R. 2.101 and 12.212 (<strong>for</strong> non-DoD<br />

acquisitions).<br />

REPORT<br />

You may wish to report any ambiguities, inconsistencies or inaccuracies you may find in connection with your evaluation of the Specification<br />

("Feedback"). To the extent that you provide Sun with any Feedback, you hereby: (i) agree that such Feedback is provided on a non-proprietary and<br />

non-confidential basis, and (ii) grant Sun a perpetual, non-exclusive, worldwide, fully paid-up, irrevocable license, with the right to sublicense<br />

through multiple levels of sublicensees, to incorporate, disclose, and use without limitation the Feedback <strong>for</strong> any purpose related to the Specification<br />

and future versions, implementations, and test suites thereof.<br />

GENERAL TERMS<br />

Any action related to this Agreement will be governed by Cali<strong>for</strong>nia law and controlling U.S. federal law. The U.N. Convention <strong>for</strong> the International<br />

Sale of Goods and the choice of law rules of any jurisdiction will not apply.<br />

The Specification is subject to U.S. export control laws and may be subject to export or import regulations in other countries. Licensee agrees to<br />

comply strictly with all such laws and regulations and acknowledges that it has the responsibility to obtain such licenses to export, re-export or import<br />

as may be required after delivery to Licensee.<br />

Neither party may assign or otherwise transfer any of its rights or obligations under this Agreement, without the prior written consent of the other<br />

party, except that Sun may assign this Agreement to an affiliated company.<br />

This Agreement is the parties’ entire agreement relating to its subject matter. It supersedes all prior or contemporaneous oral or written communic<br />

ations, proposals, conditions, representations and warranties and prevails over any conflicting or additional terms of any quote, order, acknowledgment,<br />

or other communication between the parties relating to its subject matter during the term of this Agreement. No modification to this Agreement will<br />

be binding, unless in writing and signed by an authorized representative of each party.


Community Draft<br />

Community Draft<br />

Table of Contents<br />

1. Open Issues ..................................................................................................................................... 1<br />

2. Overview ........................................................................................................................................ 3<br />

What is <strong>XML</strong>? ............................................................................................................................ 3<br />

<strong>XML</strong> and the <strong>Java</strong> Plat<strong>for</strong>m ........................................................................................................... 3<br />

About This Specification ............................................................................................................... 3<br />

Who Should Read This Document .................................................................................................. 4<br />

Report and Contact ...................................................................................................................... 4<br />

Development of This Specification ................................................................................................. 4<br />

Acknowledgments ....................................................................................................................... 5<br />

3. Endorsed Specifications ..................................................................................................................... 6<br />

Extensible Markup Language (<strong>XML</strong>) .............................................................................................. 6<br />

Namespaces in <strong>XML</strong> .................................................................................................................... 6<br />

<strong>XML</strong> Schema ............................................................................................................................. 6<br />

XSL Trans<strong>for</strong>mations (XSLT) ........................................................................................................ 6<br />

<strong>XML</strong> Path Language (XPath) ......................................................................................................... 7<br />

<strong>XML</strong> Inclusions (XInclude) ........................................................................................................... 7<br />

Document Object Model (DOM) Level 3 ......................................................................................... 7<br />

Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX) .......................................................................................................... 7<br />

4. Plugability Layer .............................................................................................................................. 9<br />

SAX Plugability .......................................................................................................................... 9<br />

Examples ........................................................................................................................... 9<br />

DOM Plugability ....................................................................................................................... 10<br />

Reliance on SAX <strong>API</strong> ......................................................................................................... 11<br />

Examples ......................................................................................................................... 11<br />

XSLT Plugability ....................................................................................................................... 12<br />

Examples ......................................................................................................................... 12<br />

Thread Safety ............................................................................................................................ 17<br />

Properties For Enabling Schema Validation .................................................................................... 18<br />

Samples Using the Properties ............................................................................................... 20<br />

Recommended Implementation of Properties ................................................................................... 21<br />

5. Con<strong>for</strong>mance Requirements .............................................................................................................. 22<br />

6. <strong>XML</strong> Inclusions (XInclude) .............................................................................................................. 23<br />

What is <strong>XML</strong> Inclusions (XInclude) .............................................................................................. 23<br />

Implementation Required by <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> ................................... 23<br />

7. <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Specification and Implementation Version In<strong>for</strong>mation ..... 24<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Specification Version In<strong>for</strong>mation ............................ 24<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Implementation Version In<strong>for</strong>mation ........................ 24<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Full Specification and Implementation Version In<strong>for</strong>m<br />

ation ........................................................................................................................................ 24<br />

8. Package javax.xml.parsers ................................................................................................................ 26<br />

Class DocumentBuilder ............................................................................................................... 26<br />

Synopsis .......................................................................................................................... 26<br />

Members .......................................................................................................................... 27<br />

Class DocumentBuilderFactory .................................................................................................... 31<br />

Synopsis .......................................................................................................................... 31<br />

Members .......................................................................................................................... 32<br />

Class SAXParser ....................................................................................................................... 38<br />

Synopsis .......................................................................................................................... 39<br />

Members .......................................................................................................................... 40<br />

Class SAXParserFactory ............................................................................................................. 48<br />

Synopsis .......................................................................................................................... 48<br />

iv


Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong><br />

Community Draft<br />

Members .......................................................................................................................... 49<br />

Exception ParserConfigurationException ........................................................................................ 54<br />

Synopsis .......................................................................................................................... 54<br />

Members .......................................................................................................................... 54<br />

Error FactoryConfigurationError ................................................................................................... 55<br />

Synopsis .......................................................................................................................... 55<br />

Members .......................................................................................................................... 55<br />

9. Package javax.xml.trans<strong>for</strong>m ............................................................................................................ 57<br />

Creating Objects ........................................................................................................................ 57<br />

Specification of Inputs and Outputs ....................................................................................... 57<br />

Class OutputKeys ...................................................................................................................... 59<br />

Synopsis .......................................................................................................................... 59<br />

Members .......................................................................................................................... 59<br />

Class Trans<strong>for</strong>mer ...................................................................................................................... 62<br />

Synopsis .......................................................................................................................... 62<br />

Members .......................................................................................................................... 63<br />

Class Trans<strong>for</strong>merFactory ............................................................................................................ 68<br />

Synopsis .......................................................................................................................... 68<br />

Members .......................................................................................................................... 69<br />

Interface ErrorListener ................................................................................................................ 73<br />

Synopsis .......................................................................................................................... 73<br />

Members .......................................................................................................................... 74<br />

Interface Result ......................................................................................................................... 75<br />

Synopsis .......................................................................................................................... 75<br />

Members .......................................................................................................................... 75<br />

Interface Source ......................................................................................................................... 76<br />

Synopsis .......................................................................................................................... 76<br />

Members .......................................................................................................................... 76<br />

Interface SourceLocator .............................................................................................................. 77<br />

Synopsis .......................................................................................................................... 77<br />

Members .......................................................................................................................... 77<br />

Interface Templates .................................................................................................................... 78<br />

Synopsis .......................................................................................................................... 78<br />

Members .......................................................................................................................... 79<br />

Interface URIResolver ................................................................................................................ 79<br />

Synopsis .......................................................................................................................... 79<br />

Members .......................................................................................................................... 80<br />

Exception Trans<strong>for</strong>merConfigurationException ............................................................................... 80<br />

Synopsis .......................................................................................................................... 80<br />

Members .......................................................................................................................... 81<br />

Exception Trans<strong>for</strong>merException .................................................................................................. 82<br />

Synopsis .......................................................................................................................... 82<br />

Members .......................................................................................................................... 83<br />

Error Trans<strong>for</strong>merFactoryConfigurationError .................................................................................. 87<br />

Synopsis .......................................................................................................................... 87<br />

Members .......................................................................................................................... 87<br />

10. Package javax.xml.trans<strong>for</strong>m.dom .................................................................................................... 89<br />

Class DOMResult ...................................................................................................................... 89<br />

Synopsis .......................................................................................................................... 89<br />

Members .......................................................................................................................... 90<br />

Class DOMSource ..................................................................................................................... 94<br />

Synopsis .......................................................................................................................... 94<br />

Members .......................................................................................................................... 95<br />

Interface DOMLocator ................................................................................................................ 96<br />

v


Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong><br />

Community Draft<br />

Synopsis .......................................................................................................................... 96<br />

Members .......................................................................................................................... 96<br />

11. Package javax.xml.trans<strong>for</strong>m.sax ..................................................................................................... 97<br />

Class SAXResult ....................................................................................................................... 97<br />

Synopsis .......................................................................................................................... 98<br />

Members .......................................................................................................................... 98<br />

Class SAXSource ..................................................................................................................... 100<br />

Synopsis ......................................................................................................................... 100<br />

Members ........................................................................................................................ 100<br />

Class SAXTrans<strong>for</strong>merFactory ................................................................................................... 102<br />

Synopsis ......................................................................................................................... 103<br />

Members ........................................................................................................................ 103<br />

Interface TemplatesHandler ........................................................................................................ 106<br />

Synopsis ......................................................................................................................... 106<br />

Members ........................................................................................................................ 106<br />

Interface Trans<strong>for</strong>merHandler ..................................................................................................... 106<br />

Synopsis ......................................................................................................................... 107<br />

Members ........................................................................................................................ 107<br />

12. Package javax.xml.trans<strong>for</strong>m.stream ............................................................................................... 109<br />

Class StreamResult ................................................................................................................... 109<br />

Synopsis ......................................................................................................................... 109<br />

Members ........................................................................................................................ 110<br />

Class StreamSource .................................................................................................................. 112<br />

Synopsis ......................................................................................................................... 112<br />

Members ........................................................................................................................ 113<br />

13. Package javax.xml.namespace ....................................................................................................... 117<br />

Class QName .......................................................................................................................... 117<br />

Synopsis ......................................................................................................................... 117<br />

Members ........................................................................................................................ 118<br />

Interface NamespaceContext ...................................................................................................... 122<br />

Synopsis ......................................................................................................................... 122<br />

Members ........................................................................................................................ 123<br />

14. Package javax.xml.xpath .............................................................................................................. 126<br />

About XPath ........................................................................................................................... 126<br />

XPath Examples ............................................................................................................... 126<br />

Class XPathConstants ............................................................................................................... 128<br />

Synopsis ......................................................................................................................... 128<br />

Members ........................................................................................................................ 129<br />

Class XPathFactory .................................................................................................................. 130<br />

Synopsis ......................................................................................................................... 130<br />

Members ........................................................................................................................ 130<br />

Interface XPath ........................................................................................................................ 131<br />

Synopsis ......................................................................................................................... 132<br />

Members ........................................................................................................................ 133<br />

Interface XPathExpression ......................................................................................................... 139<br />

Synopsis ......................................................................................................................... 140<br />

Members ........................................................................................................................ 140<br />

Interface XPathFunction ............................................................................................................ 144<br />

Synopsis ......................................................................................................................... 144<br />

Members ........................................................................................................................ 144<br />

Interface XPathFunctionResolver ................................................................................................ 145<br />

Synopsis ......................................................................................................................... 145<br />

Members ........................................................................................................................ 145<br />

Interface XPathVariableResolver ................................................................................................ 146<br />

vi


Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong><br />

Community Draft<br />

Synopsis ......................................................................................................................... 146<br />

Members ........................................................................................................................ 146<br />

Exception XPathException ......................................................................................................... 147<br />

Synopsis ......................................................................................................................... 147<br />

Members ........................................................................................................................ 147<br />

Exception XPathExpressionException .......................................................................................... 148<br />

Synopsis ......................................................................................................................... 148<br />

Members ........................................................................................................................ 149<br />

Exception XPathFactoryConfigurationException ............................................................................ 150<br />

Synopsis ......................................................................................................................... 150<br />

Members ........................................................................................................................ 151<br />

Exception XPathFunctionException ............................................................................................. 152<br />

Synopsis ......................................................................................................................... 152<br />

Members ........................................................................................................................ 152<br />

15. Package javax.xml.validation ........................................................................................................ 154<br />

Class AbstractSchemaImpl ......................................................................................................... 154<br />

Synopsis ......................................................................................................................... 154<br />

Members ........................................................................................................................ 154<br />

Class Schema .......................................................................................................................... 155<br />

Synopsis ......................................................................................................................... 155<br />

Members ........................................................................................................................ 156<br />

Class SchemaFactory ................................................................................................................ 156<br />

Schema Language ............................................................................................................ 156<br />

Synopsis ......................................................................................................................... 157<br />

Members ........................................................................................................................ 158<br />

Class SchemaFactoryFinder ....................................................................................................... 167<br />

Resolution Process ........................................................................................................... 167<br />

Synopsis ......................................................................................................................... 168<br />

Members ........................................................................................................................ 169<br />

Class SchemaFactoryLoader ....................................................................................................... 169<br />

Synopsis ......................................................................................................................... 170<br />

Members ........................................................................................................................ 170<br />

Class TypeInfoProvider ............................................................................................................. 171<br />

Synopsis ......................................................................................................................... 171<br />

Members ........................................................................................................................ 171<br />

Class Validator ........................................................................................................................ 174<br />

Synopsis ......................................................................................................................... 174<br />

Members ........................................................................................................................ 175<br />

Class ValidatorHandler ............................................................................................................. 181<br />

Recognized Properties and Features ..................................................................................... 182<br />

Synopsis ......................................................................................................................... 182<br />

Members ........................................................................................................................ 183<br />

16. Package javax.xml.datatype ........................................................................................................... 190<br />

Class Duration ......................................................................................................................... 190<br />

Order relationship ............................................................................................................ 190<br />

Synopsis ......................................................................................................................... 191<br />

Members ........................................................................................................................ 192<br />

Class Duration.Field ................................................................................................................. <strong>206</strong><br />

Synopsis ......................................................................................................................... <strong>206</strong><br />

Members ........................................................................................................................ <strong>206</strong><br />

Class <strong>XML</strong>GregorianCalendar .................................................................................................... <strong>206</strong><br />

Synopsis ......................................................................................................................... 209<br />

Members ........................................................................................................................ 212<br />

17. Package javax.xml ....................................................................................................................... 233<br />

vii


Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong><br />

Community Draft<br />

Class AbstractVersion ............................................................................................................... 233<br />

Synopsis ......................................................................................................................... 233<br />

Members ........................................................................................................................ 234<br />

Class Secure<strong>Processing</strong> ............................................................................................................. 234<br />

Synopsis ......................................................................................................................... 234<br />

Members ........................................................................................................................ 235<br />

Class Version .......................................................................................................................... 236<br />

Synopsis ......................................................................................................................... 237<br />

Members ........................................................................................................................ 237<br />

Class VersionImpl .................................................................................................................... 239<br />

Synopsis ......................................................................................................................... 239<br />

Members ........................................................................................................................ 240<br />

Class <strong>XML</strong>Constants ................................................................................................................ 241<br />

Synopsis ......................................................................................................................... 241<br />

Members ........................................................................................................................ 241<br />

Class <strong>XML</strong>Utils ....................................................................................................................... 243<br />

Synopsis ......................................................................................................................... 243<br />

Members ........................................................................................................................ 244<br />

18. Change History ........................................................................................................................... 246<br />

From 1.1 final release to 1.2 final release ...................................................................................... 246<br />

From 1.1 Proposed Final Draft to 1.1 Final Release ......................................................................... 246<br />

From 1.1 Public Review 2 to Proposed Final Draft .......................................................................... 246<br />

From 1.1 Public Review 1 to 1.1 Public Review 2 .......................................................................... 246<br />

From 1.0 Final Release to 1.1 Public Review ................................................................................. 246<br />

From 1.0 Public Release to 1.0 Final Release ................................................................................. 247<br />

From 1.0 Public Review to 1.0 Public Release ............................................................................... 247<br />

A. Change Log ................................................................................................................................ 248<br />

19. Colophon ................................................................................................................................... 249<br />

Talk the Talk, Walk the Walk ..................................................................................................... 249<br />

viii


Community Draft<br />

Community Draft<br />

List of Tables<br />

19.1. <strong>XML</strong> Usage Conventions ........................................................................................................... 249<br />

ix


Community Draft<br />

Community Draft<br />

Chapter 1. Open Issues<br />

Introduction<br />

The <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Expert Group would like to thank participants in the <strong>Java</strong><br />

Community that are reviewing this <strong>Java</strong> Specification Request. All comments, feedback and guidance from the <strong>Java</strong><br />

Community is appreciated.<br />

Please submit comments to .<br />

A dynamic version of the open issues and electronic artifacts is being maintained at <strong>JSR</strong><strong>206</strong>-Public.Dev.<strong>Java</strong>.Net<br />

[http://jsr<strong>206</strong>-public.dev.java.net/] under File sharing [https://jsr<strong>206</strong>-public.dev.java.net/servlets/ProjectDocumentList]<br />

in Project tools. Please see this on-line version <strong>for</strong> the most current open issues and electronic artifacts.<br />

If you are viewing this on-line and wish to have the links resolve to a downloaded copy of the<br />

Public Draft, take the following steps:<br />

1. Download the Public Draft in XHTML or HTML <strong>for</strong>mat from <strong>JSR</strong><strong>206</strong>-Public.Dev.<strong>Java</strong>.Net<br />

[http://jsr<strong>206</strong>-public.dev.java.net/] under File sharing<br />

[https://jsr<strong>206</strong>-public.dev.java.net/servlets/ProjectDocumentList] in Project tools.<br />

2. Unzip the downloaded file into a local directory.<br />

3. Save this file into the downloaded directory. If you downloaded the XHTML version of the Public Draft, download<br />

the XHTML version of this document. If you downloaded the HTML version of the Public Draft, download the<br />

HTML version of this document.<br />

4. All links in this document are relative links so they will now be resolved to the local copy of the specification.<br />

The Expert Group would like to call specific attention to and solicit explicit feedback and guidance on the following<br />

parts of the <strong>API</strong>.<br />

<strong>XML</strong> 1.1 and SAX<br />

In order to process <strong>XML</strong> 1.1, one must use SAX extensions [http://www.saxproject.org/?selected=ext]. The SAX ex<br />

tensions are are labeled "beta1". Although labeled "beta1", they have been stable and in wide use <strong>for</strong> a long period of<br />

time.<br />

Input [mailto:<strong>JSR</strong>-<strong>206</strong>-comments@JCP.org] is requested as to if it is acceptable to use the SAX extensions as they<br />

exist today or an ef<strong>for</strong>t in the SAX community should be made to:<br />

1. move the SAX extensions to a "final" designation<br />

2. move the SAX extensions necessary <strong>for</strong> <strong>XML</strong> 1.1 to SAX core<br />

Validation<br />

Validation has now been decoupled from parsing. It is now possible to parse/process/cache/etc grammars with the<br />

javax.xml.validation package. Input [mailto:<strong>JSR</strong>-<strong>206</strong>-comments@JCP.org] is requested <strong>for</strong> reasonable use cases <strong>for</strong><br />

<strong>for</strong> both J2SE and J2EE applications to insure that the full spectrum of expectations and needs are met.<br />

Secure <strong>Processing</strong><br />

There are several known Denial of Service exploits when processing <strong>XML</strong>. Some security exposures are inherit in the<br />

<strong>XML</strong> processing model and some are implementation dependent.<br />

1


Community Draft<br />

Open Issues<br />

Community Draft<br />

A preliminary Secure <strong>Processing</strong> model, javax.xml.Secure<strong>Processing</strong>, has been included in this Public Draft. It is ex<br />

pected that this security model will change based on Public Review.<br />

Input [mailto:<strong>JSR</strong>-<strong>206</strong>-comments@JCP.org] is requested as to the desired security model that insures interoperability<br />

yet allows <strong>for</strong> implementation dependent secure processing as required by the application. Examples would include:<br />

boolean set/get method<br />

property/feature<br />

XInclude <strong>Processing</strong><br />

The ability to enable/disable/query the state of XInclude processing is available <strong>for</strong> javax.xml.parsers.DocumentBuild<br />

erFactory and javax.xml.parsers.SAXParserFactory . The Expert Group has not been provided nor able to determine<br />

any reasonable use cases to provide the ability to modify the state of XInclude processing <strong>for</strong> javax.xml.parsers.Doc<br />

umentBuilder and javax.xml.parsers.SAXParser . Input [mailto:<strong>JSR</strong>-<strong>206</strong>-comments@JCP.org] is requested <strong>for</strong> reas<br />

onable use cases that require such functionality.<br />

2


Community Draft<br />

Community Draft<br />

Chapter 2. Overview<br />

What is <strong>XML</strong>?<br />

<strong>XML</strong> is the meta language defined by the World Wide Web Consortium (W3C) that can be used to describe a broad<br />

range of hierarchical mark up languages. It is a set of rules, guidelines, and conventions <strong>for</strong> describing structured data<br />

in a plain text, editable file. Using a text <strong>for</strong>mat instead of a binary <strong>for</strong>mat allows the programmer or even an end user<br />

to look at or utilize the data without relying on the program that produced it. However the primary producer and consumer<br />

of <strong>XML</strong> data is the computer program and not the end-user.<br />

Like HTML, <strong>XML</strong> makes use of tags and attributes. Tags are words bracketed by the "&lt;" and "&gt;" characters<br />

and attributes are strings of the <strong>for</strong>m ’name="value"’ that are inside of tags. While HTML specifies what each tag<br />

and attribute means, as well as their presentation attributes in a browser, <strong>XML</strong> uses tags only to delimit pieces of data<br />

and leaves the interpretation of the data to the application that uses it. In other words, <strong>XML</strong> defines only the structure<br />

of the document and does not define any of the presentation semantics of that document.<br />

Development of <strong>XML</strong> started in 1996 leading to a W3C Recommendation in February of 1998. However, the technology<br />

is not entirely new. It is based on SGML (Standard Generalized Markup Language) which was developed in the early<br />

1980’s and became an ISO standard in 1986. SGML has been widely used <strong>for</strong> large documentation projects and there<br />

is a large community that has experience working with SGML. The designers of <strong>XML</strong> took the best parts of SGML,<br />

used their experience as a guide and produced a technology that is just as powerful as SGML, but much simpler and<br />

easier to use.<br />

<strong>XML</strong>-based documents can be used in a wide variety of applications including vertical markets, e-commerce, businessto-business<br />

communication, and enterprise application messaging.<br />

<strong>XML</strong> and the <strong>Java</strong> Plat<strong>for</strong>m<br />

In many ways, <strong>XML</strong> and the <strong>Java</strong> Plat<strong>for</strong>m are a partnership made in heaven. <strong>XML</strong> defines a cross plat<strong>for</strong>m data <strong>for</strong>mat<br />

and <strong>Java</strong> provides a standard cross plat<strong>for</strong>m programming plat<strong>for</strong>m. Together, <strong>XML</strong> and <strong>Java</strong> technologies allow pro<br />

grammers to apply Write Once, Run Anywhere fundamentals to the processing of data and documents generated by<br />

both <strong>Java</strong> based programs and non-<strong>Java</strong> based programs.<br />

About This Specification<br />

This document describes the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong>, Version <strong>1.3</strong>. This version of the specification introduces<br />

basic support <strong>for</strong> parsing and manipulating <strong>XML</strong> documents through a standardized set of <strong>Java</strong> Plat<strong>for</strong>m <strong>API</strong>s.<br />

When this specification is final there will be a Reference Implementation which will demonstrate the capabilities of<br />

this <strong>API</strong> and will provide an operational definition of the specification. A Technology Compatibility Kit (TCK) will<br />

also be available that will verify whether an implementation of this specification is compliant. These are required as<br />

per the <strong>Java</strong> Community Process 2.5 (JCP 2.5).<br />

Note<br />

<strong>API</strong> references are accompanied by a small-font subscript that gives the page on which the <strong>API</strong> is defined.<br />

For example:<br />

newDocumentBuilder<br />

3


Community Draft<br />

Overview<br />

Community Draft<br />

Who Should Read This Document<br />

This specification is intended <strong>for</strong> use by:<br />

• Parser Developers wishing to implement this version of the specification in their parser.<br />

• Application Developers who use the <strong>API</strong>s described in this specification and wish to have a more complete under<br />

standing of the <strong>API</strong>.<br />

Note<br />

We are looking <strong>for</strong> feedback on the XPath <strong>API</strong> in the javax.xml.xpath package. This is new functionality that<br />

we are adding in <strong>JSR</strong> <strong>206</strong> along with Grammar Caching. We want this <strong>API</strong> to be extensible so that it is easy<br />

to build XPath 2.0 functionality on top of this <strong>API</strong>. Please keep this goal in mind while reviewing the XPath<br />

<strong>API</strong>.<br />

This specification is not a tutorial or a user’s guide to <strong>XML</strong>, DOM, SAX or XSLT. Familiarity with these technologies<br />

and specifications on the part of the reader is assumed.<br />

Report and Contact<br />

Your comments on this specification are welcome and appreciated. Without your comments, the specifications developed<br />

under the auspices of the <strong>Java</strong> Community Process would not serve your needs as well. To comment on this specification,<br />

please send email to .<br />

You can stay current with Sun’s <strong>Java</strong> Plat<strong>for</strong>m related activities, as well as in<strong>for</strong>mation on our <br />

and mailing lists, at our website [http://java.sun.com/xml/jaxp].<br />

Development of This Specification<br />

This specification was developed in accordance with the <strong>Java</strong> Community Process [http://www.jcp.org] 2.5. It was<br />

developed under the authorization of <strong>Java</strong> Specification Request <strong>206</strong> [http://jcp.org/en/jsr/detail?id=<strong>206</strong>].<br />

The expert group who contributed to this specification is composed of individuals from a number of companies. These<br />

individuals are:<br />

• Jeff Suttor (Specification Lead), Sun Microsystems, Inc.<br />

• Norm Walsh (Specification Lead), Sun Microsystems, Inc.<br />

• Kohsuke Kawaguchi (Markup Geek), Sun Microsystems, Inc.<br />

• Ben Galbraith<br />

• Neil Graham, IBM<br />

• Phil Hanna, SAS Institute Inc.<br />

• Todd Karakashian, bea<br />

• K. Karun, <strong>Oracle</strong><br />

• Dongeun Kim, Tmax Soft, Inc.<br />

4


Community Draft<br />

Overview<br />

Community Draft<br />

• Harish Krishnaswamy, Novell, Inc.<br />

• Miles Sabin<br />

• Vladimir Savchenko, SAP AG<br />

• Ilene Seelemann, IBM<br />

• Henry Zongaro, IBM<br />

We would like to acknowledge that a lot of the grammar caching work introduced in this version of the specification<br />

was derived from the work being done under the Xerces project at Apache.<br />

Acknowledgments<br />

Many individuals and companies have given their time and talents to make this specification, or the specifications that<br />

this specification relies upon, a reality. The authors of this specification would like to thank (in no particular order):<br />

• David Brownell, David Megginson and the <strong>XML</strong>-DEV community who developed the SAX <strong>API</strong><br />

• The W3C DOM Working Group chaired by Philippe Le Hégaret<br />

• The Apache <strong>Software</strong> Foundation [http://apache.org/], <strong>for</strong> Xerces and Xalan<br />

• Michael Kay, <strong>Software</strong> AG<br />

• Elliotte Rusty Harold, Cafe con Leche <strong>XML</strong> News and Resources [http://www.cafeconleche.org/], Cafe au Lait<br />

<strong>Java</strong> News and Resources [http://www.cafeaulait.org/]<br />

• Han Ming Ong, Apple<br />

• Eduardo Pelegri-Lopart, Tom Kincaid, Connie Weiss, Gopal Sharma, Neeraj Bajaj, K. Venugopal, Arun Yadav,<br />

Ramesh Mandava, Bhakti Mehta, Prasad Subramanian, Todd Miller, Joesph Fialli, and Rajiv Mordani all of whom<br />

work at Sun Microsystems, Inc. and whose talents have all reflected upon the development of this <strong>API</strong>.<br />

• Margaret, Mark, Magita and the unmet trans<strong>for</strong>mative change agents who remind us that with trust and commitment,<br />

"it’s all true."<br />

5


Community Draft<br />

Community Draft<br />

Chapter 3. Endorsed Specifications<br />

This specification endorses and builds upon several external specifications. Each specification endorsed by this document<br />

is called out together with the exact version of the specification and its publicly accessible location. All of these<br />

standards have con<strong>for</strong>mance tests provided in the Technology Compatibility Kit available <strong>for</strong> this specification.<br />

Extensible Markup Language (<strong>XML</strong>)<br />

This specification supports Extensible Markup Language (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11], Extensible<br />

Markup Language (<strong>XML</strong>) 1.0 (Second Edition) [http://www.w3.org/TR/REC-xml] and Extensible Markup Language<br />

(<strong>XML</strong>) 1.0 (Second Edition) Errata [http://www.w3.org/<strong>XML</strong>/xml-V10-2e-errata]<br />

<strong>XML</strong> is a product of the W3C <strong>XML</strong> Activity [http://www.w3.org/<strong>XML</strong>/].<br />

This specification includes by reference Extensible Markup Language (<strong>XML</strong>) 1.1, Extensible Markup Language (<strong>XML</strong>)<br />

1.0 (Second Edition) and Extensible Markup Language (<strong>XML</strong>) 1.0 (Second Edition) Errata in their entirety <strong>for</strong> the<br />

purposes of defining <strong>XML</strong> in the <strong>API</strong>s defined herein.<br />

Namespaces in <strong>XML</strong><br />

This specification supports Namespaces in <strong>XML</strong> 1.1. [http://www.w3.org/TR/xml-names11/], Namespaces in <strong>XML</strong><br />

1.0 [http://www.w3.org/TR/REC-xml-names] and Namespaces in <strong>XML</strong> 1.0 Errata<br />

[http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata].<br />

Namespaces in <strong>XML</strong> is a product of the W3C <strong>XML</strong> Activity [http://www.w3.org/<strong>XML</strong>/].<br />

This specification includes by reference Namespaces in <strong>XML</strong> 1.1, Namespaces in <strong>XML</strong> 1.0 and Namespaces in <strong>XML</strong><br />

1.0 Errata, in their entirety <strong>for</strong> the purposes of defining Namespaces in <strong>XML</strong> in the <strong>API</strong>s defined herein.<br />

<strong>XML</strong> Schema<br />

This specification supports <strong>XML</strong> Schema Part 1: Structures [http://www.w3.org/TR/xmlschema-1/], <strong>XML</strong> Schema<br />

Part 1: Structures Errata [http://www.w3.org/2001/05/xmlschema-errata#Errata1], <strong>XML</strong> Schema Part 2: Datatypes<br />

[http://www.w3.org/TR/xmlschema-2/] and <strong>XML</strong> Schema Part 2: Datatypes Errata<br />

[http://www.w3.org/2001/05/xmlschema-errata#Errata2].<br />

<strong>XML</strong> Schema is a product of the <strong>XML</strong> Schema Working Group [http://www.w3.org/<strong>XML</strong>/Schema].<br />

This specification includes by reference <strong>XML</strong> Schema Part 1: Structures, <strong>XML</strong> Schema Part 1: Structures Errata, <strong>XML</strong><br />

Schema Part 2: Datatypes and <strong>XML</strong> Schema Part 2: Datatypes Errata in their entirety <strong>for</strong> the purposes of defining<br />

<strong>XML</strong> Schema in the <strong>API</strong>s defined herein.<br />

XSL Trans<strong>for</strong>mations (XSLT)<br />

This specification supports XSL Trans<strong>for</strong>mations (XSLT) Version 1.0 [http://www.w3.org/TR/xslt].<br />

XSLT is a product of the W3C Style Activity [http://www.w3.org/Style/Activity].<br />

This specification includes by reference XSL Trans<strong>for</strong>mations (XSLT) Version 1.0 in its entirety <strong>for</strong> the purposes of<br />

defining XSLT in the <strong>API</strong>s defined herein.<br />

6


Community Draft<br />

Endorsed Specifications<br />

Community Draft<br />

<strong>XML</strong> Path Language (XPath)<br />

This specification supports <strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath] and <strong>XML</strong> Path<br />

Language (XPath) Version 1.0 Errata [http://www.w3.org/1999/11/REC-xpath-19991116-errata].<br />

XPath is a product of the W3C <strong>XML</strong> Activity [http://www.w3.org/<strong>XML</strong>/Activity] and W3C Style Activity<br />

[http://www.w3.org/Style/Activity].<br />

This specification includes by reference <strong>XML</strong> Path Language (XPath) Version 1.0 and <strong>XML</strong> Path Language (XPath)<br />

Version 1.0 Errata in their entirety <strong>for</strong> the purposes of defining SAX in the <strong>API</strong>s defined herein.<br />

<strong>XML</strong> Inclusions (XInclude)<br />

This specification supports <strong>XML</strong> Inclusions (XInclude) Version 1.0 [http://www.w3.org/TR/xinclude/].<br />

XInclude is a product of the W3C <strong>XML</strong> Core Working Group [http://www.w3.org/<strong>XML</strong>/Core/] as part of the W3C<br />

<strong>XML</strong> Activity [http://www.w3.org/<strong>XML</strong>/Activity].<br />

This specification includes by reference <strong>XML</strong> Inclusions (XInclude) Version 1.0. in its entirety <strong>for</strong> the purposes of<br />

defining XInclude in the <strong>API</strong>s defined herein.<br />

Document Object Model (DOM) Level 3<br />

This specification supports Document Object Model (DOM) Level 3 Core [http://www.w3.org/TR/DOM-Level-3-Core]<br />

and Document Object Model (DOM) Level 3 Load and Save [http://www.w3.org/TR/DOM-Level-3-LS].<br />

DOM Level 3 is a product of the W3C DOM Activity [http://www.w3.org/DOM/].<br />

This specification includes by reference Document Object Model (DOM) Level 3 Core and Document Object Model<br />

(DOM) Level 3 Load and Save in their entirety <strong>for</strong> the purposes of defining SAX in the <strong>API</strong>s defined herein.<br />

The <strong>API</strong> packages included by reference are:<br />

• org.w3c.dom<br />

• org.w3c.dom.bootstrap<br />

• org.w3c.dom.ls<br />

• org.w3c.dom.ranges<br />

• org.w3c.dom.traversal<br />

Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX)<br />

This specification supports Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX) 2.0.1 (sax2 r2) [http://www.saxproject.org/] and Simple <strong>API</strong><br />

<strong>for</strong> <strong>XML</strong> (SAX) 2.0.1 (sax2 r2) Extensions [http://www.saxproject.org/?selected=ext].<br />

SAX is a product of the SAX Community [http://www.saxproject.org/].<br />

This specification includes by reference Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX) 2.0.1 (sax2 r2) and Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX)<br />

2.0.1 (sax2 r2) Extensions in their entirety <strong>for</strong> the purposes of defining SAX in the <strong>API</strong>s defined herein.<br />

7


Community Draft<br />

Endorsed Specifications<br />

Community Draft<br />

The <strong>API</strong> packages included by reference are:<br />

• org.xml.sax<br />

• org.xml.sax.ext<br />

• org.xml.sax.helpers<br />

8


Community Draft<br />

Community Draft<br />

Chapter 4. Plugability Layer<br />

The endorsed <strong>API</strong>s provide broad and useful functionality. However, the use of a SAX or a DOM parser typically requires<br />

knowledge of the specific implementation of the parser. Providing the functionality of the endorsed <strong>API</strong>s in the <strong>Java</strong><br />

Plat<strong>for</strong>m, while allowing choice of the implementation of the parser, requires a Plugability layer.<br />

This section of the specification defines a Plugability mechanism to allow a compliant SAX or DOM parser to be used<br />

through the abstract javax.xml.parsers and javax.xml.trans<strong>for</strong>m <strong>API</strong>.<br />

SAX Plugability<br />

Examples<br />

The SAX Plugability classes allow an application programmer to provide an implementation of the<br />

org.xml.sax.DefaultHandler <strong>API</strong> to a SAXParser implementation and parse <strong>XML</strong> documents. As the<br />

parser processes the <strong>XML</strong> document, it will call methods on the provided DefaultHandler.<br />

In order to obtain a SAXParser instance, an application programmer first obtains an instance of a SAXParserFact<br />

ory. The SAXParserFactory instance is obtained via the static newInstance method of the SAXParserFact<br />

ory class.<br />

This method uses the following ordered lookup procedure to determine the SAXParserFactory implementation class<br />

to load:<br />

• Use the javax.xml.parsers.SAXParserFactory system property.<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the key being<br />

the system property defined above. The jaxp.properties file is read only once by the <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implementation and it’s values are then cached <strong>for</strong> future use. If the file does not exist when<br />

the first attempt is made to read from it, no further attempts are made to check <strong>for</strong> its existence. It is not possible<br />

to change the value of any property in jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> the classname in the file META-INF/services/javax.xml.parsers.SAXParserFactory in jars<br />

available to the runtime.<br />

• Plat<strong>for</strong>m default SAXParserFactory instance.<br />

If the SAXParserFactory implementation class cannot be loaded or instantiated at runtime, a FactoryConfig<br />

urationError is thrown. This error message should contain a descriptive explanation of the problem and how the<br />

user can resolve it.<br />

The instance of SAXParserFactory can optionally be configured by the application programmer to provide parsers<br />

that are namespace aware, or validating, or both. These settings are made using the setNamespaceAware and<br />

setValidating methods of the factory. The application programmer can then obtain a SAXParser implementation<br />

instance from the factory. If the factory cannot provide a parser configured as set by the application programmer, then<br />

a ParserConfigurationException is thrown.<br />

The following is a simple example of how to parse <strong>XML</strong> content from a URL:<br />

SAXParser parser;<br />

9


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

DefaultHandler handler = new MyApplicationParseHandler();<br />

SAXParserFactory factory = SAXParserFactory.newInstance();<br />

try {<br />

parser = factory.newSAXParser();<br />

parser.parse("http://myserver/mycontent.xml", handler);<br />

} catch (SAXException se) {<br />

// handle error<br />

} catch (IOException ioe) {<br />

// handle error<br />

} catch (ParserConfigurationException pce) {<br />

// handle error<br />

}<br />

The following is an example of how to configure a SAX parser to be namespace aware and validating:<br />

SAXParser parser;<br />

DefaultHandler handler = new MyApplicationParseHandler();<br />

SAXParserFactory factory = SAXParserFactory.newInstance();<br />

factory.setNamespaceAware(true);<br />

factory.setValidating(true);<br />

try {<br />

parser = factory.newSAXParser();<br />

parser.parse("http://myserver/mycontent.xml", handler);<br />

} catch (SAXException se) {<br />

// handle error<br />

} catch (IOException ioe) {<br />

// handle error<br />

} catch (ParserConfigurationException pce) {<br />

// handle error<br />

}<br />

An example of how one could pass the System property as a command line option is:<br />

java -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl user.parserApp<br />

DOM Plugability<br />

The DOM plugability classes allow a programmer to parse an <strong>XML</strong> document and obtain an org.w3c.dom.Docu<br />

ment object from a DocumentBuilder implementation which wraps an underlying DOM implementation.<br />

In order to obtain a DocumentBuilder instance, an application programmer first obtains an instance of a Docu<br />

mentBuilderFactory. The DocumentBuilderFactory instance is obtained via the static newInstance<br />

method of the DocumentBuilderFactory class.<br />

This method uses the following ordered lookup procedure to determine the DocumentBuilderFactory implementation<br />

class to load:<br />

• Use the javax.xml.parsers.DocumentBuilderFactory system property<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the key being<br />

10


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

the system property defined above. The jaxp.properties file is read only once by the <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implementation and it’s values are then cached <strong>for</strong> future use. If the file does not exist when<br />

the first attempt is made to read from it, no further attempts are made to check <strong>for</strong> its existence. It is not possible<br />

to change the value of any property in jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> the classname in the file META-INF/services/javax.xml.parsers.DocumentBuilderFactory in jars<br />

available to the runtime.<br />

• Plat<strong>for</strong>m default DocumentBuilderFactory instance.<br />

If the DocumentBuilderFactory implementation class cannot be loaded or instantiated at runtime, a Factory<br />

ConfigurationError is thrown. This error message should contain a descriptive explanation of the problem and<br />

how the user can resolve it.<br />

The instance of DocumentBuilderFactory can optionally be configured by the application programmer to provide<br />

parsers that are namespace aware or validating, or both. These settings are made using the setNamespaceAware<br />

and setValidating methods of the factory. The application programmer can then obtain a DocumentBuilder<br />

implementation instance from the factory. If the factory cannot provide a parser configured as set by the application<br />

programmer, then a ParserConfigurationException is thrown.<br />

Reliance on SAX <strong>API</strong><br />

Examples<br />

The DocumentBuilder reuses several classes from the SAX <strong>API</strong>. This does not mean that the implementor of the un<br />

derlying DOM implementation must use a SAX parser to parse the <strong>XML</strong> content, only that the implementation com<br />

municate with the application using these existing and defined <strong>API</strong>s.<br />

The following is a simple example of how to parse <strong>XML</strong> content from a URL:<br />

DocumentBuilder builder;<br />

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();<br />

String location = "http://myserver/mycontent.xml";<br />

try {<br />

builder = factory.newDocumentBuilder();<br />

Document document = builder.parse(location);<br />

} catch (SAXException se) {<br />

// handle error<br />

} catch (IOException ioe) {<br />

// handle error<br />

} catch (ParserConfigurationException pce) {<br />

// handle error<br />

}<br />

The following is an example of how to configure a factory to produce parsers to be namespace aware and validating:<br />

DocumentBuilder builder;<br />

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();<br />

factory.setNamespaceAware(true);<br />

factory.setValidating(true);<br />

11


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

String location = "http://myserver/mycontent.xml";<br />

try {<br />

builder = factory.newDocumentBuilder();<br />

Document document = builder.parse(location);<br />

} catch (SAXException se) {<br />

// handle error<br />

} catch (IOException ioe) {<br />

// handle error<br />

} catch (ParserConfigurationException pce) {<br />

// handle error<br />

}<br />

An example of how one could pass the System property as a command line option is:<br />

java -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl<br />

user.parserApp<br />

XSLT Plugability<br />

Examples<br />

The XSLT Plugability classes allow an application programmer to obtain a Trans<strong>for</strong>mer object that is based on a spe<br />

cific XSLT stylesheet from a Trans<strong>for</strong>merFactory implementation. In order to obtain a Trans<strong>for</strong>mer object, a programmer<br />

first obtains an instance of the Trans<strong>for</strong>merFactory. The Trans<strong>for</strong>merFactory instance is obtained via the static newIn<br />

stance method of the Trans<strong>for</strong>merFactory class.<br />

This method uses the following ordered lookup procedure to determine the Trans<strong>for</strong>merFactory implementation class<br />

to load:<br />

• Use the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory system property<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the key being<br />

the system property defined above. The jaxp.properties file is read only once by the <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implementation and it’s values are then cached <strong>for</strong> future use. If the file does not exist when<br />

the first attempt is made to read from it, no further attempts are made to check <strong>for</strong> its existence. It is not possible<br />

to change the value of any property in jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> the classname in the file META-INF/services/javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory in jars<br />

available to the runtime.<br />

• Plat<strong>for</strong>m default Trans<strong>for</strong>mFactory instance.<br />

If the Trans<strong>for</strong>merFactory implementation class cannot be loaded or instantiated at runtime, a Trans<strong>for</strong>mer<br />

FactoryConfigurationError is thrown. This error message should contain a descriptive explanation of the<br />

problem and how the user can resolve it.<br />

The following is a simple example of how to trans<strong>for</strong>m <strong>XML</strong> content:<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer;<br />

Trans<strong>for</strong>merFactory factory = Trans<strong>for</strong>merFactory.newInstance();<br />

12


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

String stylesheet = "file:///home/user/mystylesheet.xsl";<br />

String sourceId = "file:///home/user/sourcefile.xml";<br />

try {<br />

trans<strong>for</strong>mer = factory.newTrans<strong>for</strong>mer(new StreamSource(stylesheet));<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m(new StreamSource(sourceId), new StreamResult(System.out));<br />

} catch (Exception e) {<br />

// handle error<br />

}<br />

The following example illustrates the serialization of a DOM node to an <strong>XML</strong> stream:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

Trans<strong>for</strong>mer serializer = tfactory.newTrans<strong>for</strong>mer();<br />

Properties oprops = new Properties();<br />

oprops.put("method", "html");<br />

oprops.put("indent-amount", "2");<br />

serializer.setOutputProperties(oprops);<br />

serializer.trans<strong>for</strong>m(new DOMSource(doc), new StreamResult(System.out));<br />

Exceptions and Error Reporting<br />

The following example illustrates the use of the URIResolver to resolve URIs to DOM nodes, in a trans<strong>for</strong>mation<br />

whose input is totally DOM based:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(StreamResult.FEATURE))<br />

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();<br />

dfactory.setNamespaceAware(true); // Always, required <strong>for</strong> XSLT<br />

DocumentBuilder docBuilder = dfactory.newDocumentBuilder();<br />

// Set up to resolve URLs that correspond to our inc1.xsl,<br />

// to a DOM node. Use an anonymous class <strong>for</strong> the URI resolver.<br />

final Node xslInc1 = docBuilder.parse("xsl/inc1/inc1.xsl");<br />

final Node xslInc2 = docBuilder.parse("xsl/inc2/inc2.xsl");<br />

tfactory.setURIResolver(new URIResolver() {<br />

public Source resolve(String href, String base)<br />

throws Trans<strong>for</strong>merException {<br />

// ignore base.<br />

return (href.equals("inc1/inc1.xsl")) ? new DOMSource(xslInc1) : (href.equals("inc2/<br />

}<br />

}<br />

);<br />

// The Trans<strong>for</strong>merFactory will call the anonymous URI<br />

// resolver set above when it encounters<br />

// &lt;xsl:include href="inc1/inc1.xsl"/&gt;<br />

Templates templates = tfactory.newTemplates(new DOMSource(docBuilder.parse(xslID), xslID<br />

// Get a trans<strong>for</strong>mer from the templates.<br />

13


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer = templates.newTrans<strong>for</strong>mer();<br />

// Set up to resolve URLs that correspond to our foo2.xml, to<br />

// a DOM node. Use an anonymous class <strong>for</strong> the URI resolver.<br />

// Be sure to return the same DOM tree every time <strong>for</strong> the given URI.<br />

final Node xmlSubdir1Foo2Node = docBuilder.parse("xml/subdir1/foo2.xml");<br />

trans<strong>for</strong>mer.setURIResolver(new URIResolver() {<br />

public Source resolve(String href, String base)<br />

throws Trans<strong>for</strong>merException {<br />

// ignore base because we’re lazy, or we don’t care.<br />

return (href.equals("subdir1/foo2.xml")) ? new DOMSource(xmlSubdir1Foo2Node) : null;<br />

}<br />

}<br />

);<br />

// Now the trans<strong>for</strong>mer will call our anonymous URI resolver<br />

// when it encounters the document("subdir1/foo2.xml") invocation.<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m(new DOMSource(docBuilder.parse(sourceID), sourceID), new StreamRe<br />

}<br />

The following example per<strong>for</strong>ms a trans<strong>for</strong>mation using DOM nodes as input <strong>for</strong> the Trans<strong>for</strong>merFactory, as input <strong>for</strong><br />

the Trans<strong>for</strong>mer, and as the output of the trans<strong>for</strong>mation:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

// Make sure the Trans<strong>for</strong>merFactory supports the DOM feature.<br />

if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(DOMResult.FEATURE)) {<br />

// Use javax.xml.parsers to create our DOMs.<br />

DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();<br />

dfactory.setNamespaceAware(true); // do this always <strong>for</strong> XSLT<br />

DocumentBuilder docBuilder = dfactory.newDocumentBuilder();<br />

// Create the Templates from a DOM.<br />

Node xslDOM = docBuilder.parse(xslID);<br />

DOMSource dsource = new DOMSource(xslDOM, xslID);<br />

Templates templates = tfactory.newTemplates(dsource);<br />

// Create the source tree in the <strong>for</strong>m of a DOM.<br />

Node sourceNode = docBuilder.parse(sourceID);<br />

// Create a DOMResult that the trans<strong>for</strong>mation will fill in.<br />

DOMResult dresult = new DOMResult();<br />

// And trans<strong>for</strong>m from the source DOM tree to a result DOM tree.<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer = templates.newTrans<strong>for</strong>mer();<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m(new DOMSource(sourceNode, sourceID), dresult);<br />

// The root of the result tree may now be obtained from<br />

// the DOMResult object.<br />

Node out = dresult.getNode();<br />

// Serialize it to System.out <strong>for</strong> diagnostics.<br />

Trans<strong>for</strong>mer serializer = tfactory.newTrans<strong>for</strong>mer();<br />

14


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

serializer.trans<strong>for</strong>m(new DOMSource(out), new StreamResult(System.out));<br />

}<br />

The following code fragment illustrates the use of the SAXSource and SAXResult objects:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

// Does this factory support SAX features?<br />

if (tfactory.getFeature(SAXSource.FEATURE) && tfactory.getFeature(SAXResult.FEATURE)) {<br />

// Get a trans<strong>for</strong>mer.<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer = tfactory.newTrans<strong>for</strong>mer(new StreamSource(xslID));<br />

// Create a reader <strong>for</strong> reading.<br />

<strong>XML</strong>Reader reader = <strong>XML</strong>ReaderFactory.create<strong>XML</strong>Reader();<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m(new SAXSource(reader, new InputSource(sourceID)), new SAXResult(n<br />

}<br />

The following illustrates the feeding of SAX events from an org.xml.sax.<strong>XML</strong>Reader to a Trans<strong>for</strong>mer:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

// Does this factory support SAX features?<br />

if (tfactory.getFeature(SAXTrans<strong>for</strong>merFactory.FEATURE)) {<br />

// If so, we can safely cast.<br />

SAXTrans<strong>for</strong>merFactory stfactory = ((SAXTrans<strong>for</strong>merFactory) tfactory);<br />

// A Trans<strong>for</strong>merHandler is a ContentHandler that will listen <strong>for</strong><br />

// SAX events, and trans<strong>for</strong>m them to the result.<br />

Trans<strong>for</strong>merHandler handler = stfactory.newTrans<strong>for</strong>merHandler(new StreamSource(xslID));<br />

// Set the result handling to be a serialization to System.out.<br />

handler.setResult(new StreamResult(System.out));<br />

handler.getTrans<strong>for</strong>mer().setParameter("a-param", "hello to you!");<br />

// Create a reader, and set it’s content handler to be the Trans<strong>for</strong>merHandler.<br />

<strong>XML</strong>Reader reader = <strong>XML</strong>ReaderFactory.create<strong>XML</strong>Reader();<br />

reader.setContentHandler(handler);<br />

// It’s a good idea <strong>for</strong> the parser to send lexical events.<br />

// The Trans<strong>for</strong>merHandler is also a LexicalHandler.<br />

reader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);<br />

// Parse the source <strong>XML</strong>, and send the parse events to the Trans<strong>for</strong>merHandler.<br />

reader.parse(sourceID);<br />

}<br />

The following code fragment illustrates the creation of a Templates object from SAX2 events sent from an <strong>XML</strong>Reader:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

// Does this factory support SAX features?<br />

if (tfactory.getFeature(SAXTrans<strong>for</strong>merFactory.FEATURE)) {<br />

// If so, we can safely cast.<br />

SAXTrans<strong>for</strong>merFactory stfactory = ((SAXTrans<strong>for</strong>merFactory) tfactory);<br />

15


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

// Have the factory create a special ContentHandler that will<br />

// create a Templates object.<br />

TemplatesHandler handler = stfactory.newTemplatesHandler();<br />

// If you don’t do this, the TemplatesHandler won’t know how to<br />

// resolve relative URLs.<br />

handler.setSystemId(xslID);<br />

// Create a reader, and set it’s content handler to be the TemplatesHandler.<br />

<strong>XML</strong>Reader reader = <strong>XML</strong>ReaderFactory.create<strong>XML</strong>Reader();<br />

reader.setContentHandler(handler);<br />

// Parse the source <strong>XML</strong>, and send the parse events to the TemplatesHandler.<br />

reader.parse(xslID);<br />

// Get the Templates reference from the handler.<br />

Templates templates = handler.getTemplates();<br />

// Ready to trans<strong>for</strong>m.<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer = templates.newTrans<strong>for</strong>mer();<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m(new StreamSource(sourceID), new StreamResult(System.out));<br />

}<br />

The following illustrates several trans<strong>for</strong>mations chained together. Each filter points to a parent<br />

org.xml.sax.<strong>XML</strong>Reader ,and the final trans<strong>for</strong>mation is caused by invoking org.xml.sax.<strong>XML</strong>Read<br />

er#parse on the final reader in the chain:<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

// Does this factory support SAX features?<br />

if (tfactory.getFeature(SAXTrans<strong>for</strong>merFactory.FEATURE)) {<br />

Templates stylesheet1 = tfactory.newTemplates(new StreamSource(xslID_1));<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer1 = stylesheet1.newTrans<strong>for</strong>mer();<br />

SAXTrans<strong>for</strong>merFactory stf = (SAXTrans<strong>for</strong>merFactory)tfactory;<br />

<strong>XML</strong>Reader reader = <strong>XML</strong>ReaderFactory.create<strong>XML</strong>Reader();<br />

<strong>XML</strong>Filter filter1 = stf.new<strong>XML</strong>Filter(new StreamSource(xslID_1));<br />

<strong>XML</strong>Filter filter2 = stf.new<strong>XML</strong>Filter(new StreamSource(xslID_2));<br />

<strong>XML</strong>Filter filter3 = stf.new<strong>XML</strong>Filter(new StreamSource(xslID_3));<br />

// trans<strong>for</strong>mer1 will use a SAX parser as it’s reader.<br />

filter1.setParent(reader);<br />

// trans<strong>for</strong>mer2 will use trans<strong>for</strong>mer1 as it’s reader.<br />

filter2.setParent(filter1);<br />

// trans<strong>for</strong>m3 will use trans<strong>for</strong>m2 as it’s reader.<br />

filter3.setParent(filter2);<br />

filter3.setContentHandler(new ExampleContentHandler());<br />

// filter3.setContentHandler(new org.xml.sax.helpers.DefaultHandler());<br />

// Now, when you call trans<strong>for</strong>mer3 to parse, it will set<br />

// itself as the ContentHandler <strong>for</strong> trans<strong>for</strong>m2, and<br />

// call trans<strong>for</strong>m2.parse, which will set itself as the<br />

// content handler <strong>for</strong> trans<strong>for</strong>m1, and call trans<strong>for</strong>m1.parse,<br />

16


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

// which will set itself as the content listener <strong>for</strong> the<br />

// SAX parser, and call parser.parse(new InputSource("xml/foo.xml")).<br />

filter3.parse(new InputSource(sourceID));<br />

}<br />

The following code fragment illustrates the use of the stream Source and Result objects:<br />

// Create a Trans<strong>for</strong>merFactory instance.<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

InputStream xslIS = new BufferedInputStream(new FileInputStream(xslID));<br />

StreamSource xslSource = new StreamSource(xslIS);<br />

// Note that if we don’t do this, relative URLs cannot be resolved correctly!<br />

xslSource.setSystemId(xslID);<br />

// Create a trans<strong>for</strong>mer <strong>for</strong> the stylesheet.<br />

Trans<strong>for</strong>mer trans<strong>for</strong>mer = tfactory.newTrans<strong>for</strong>mer(xslSource);<br />

InputStream xmlIS = new BufferedInputStream(new FileInputStream(sourceID));<br />

StreamSource xmlSource = new StreamSource(xmlIS);<br />

// Note that if we don’t do this, relative URLs cannot be resolved correctly!<br />

xmlSource.setSystemId(sourceID);<br />

// Trans<strong>for</strong>m the source <strong>XML</strong> to System.out.<br />

trans<strong>for</strong>mer.trans<strong>for</strong>m( xmlSource, new StreamResult(System.out));<br />

An example of how one could pass the System property as a command line option is:<br />

java -Djavax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory=org.apache.xalan.processor.Trans<strong>for</strong>merFactoryImpl<br />

user.parserApp<br />

Thread Safety<br />

Implementations of the SAXParser, DocumentBuilder, Trans<strong>for</strong>mer and GrammarCache abstract classes<br />

and implementation instances of GrammarLoader are not expected to be thread safe by this specification. This means<br />

that application programmers should not expect to be able to use the same instance of a SAXParser, Document<br />

Builder, Trans<strong>for</strong>mer GrammarCache or GrammarLoader in more than one thread at a time without side<br />

effects. If a programmer is creating a multi-threaded application, they should make sure that only one thread has access<br />

to any given SAXParser, DocumentBuilder, Trans<strong>for</strong>mer, GrammarCache or GrammarLoader instance.<br />

Configuration of a SAXParserFactory, DocumentBuilderFactory Trans<strong>for</strong>merFactory or Grammar<br />

LoaderFactory is also not expected to be thread safe. This means that an application programmer should not allow<br />

a SAXParserFactory, DocumentBuilderFactory, Trans<strong>for</strong>merFactory or GrammarLoaderFactory<br />

instance to have its setter methods accessed from more than one thread.<br />

It is expected that the newSAXParser and newGrammarLoader method of a SAXParserFactory implement<br />

ation, the newDocumentBuilder and newGrammarLoader method of a DocumentBuilderFactory and<br />

the newTrans<strong>for</strong>mer method of a Trans<strong>for</strong>merFactory will be thread safe without side effects. This means<br />

that an application programmer should expect to be able to create parser instances in multiple threads at once from a<br />

shared factory without side effects or problems.<br />

17


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

Properties For Enabling Schema Validation<br />

javax.xml.parsers.SAXParserFactory<br />

The validating property must have the value true <strong>for</strong> any of the property strings defined below to take effect. Otherwise,<br />

the values of the properties defined below will be ignored. This value can be set by invoking<br />

setValidating(true)<br />

javax.xml.parsers.SAXParser<br />

The setProperty method in SAXParser must support the property strings defined below to indicate the schema language<br />

and the source of the schema file(s) to the parser:<br />

http://java.sun.com/xml/jaxp/properties/schemaLanguage<br />

This property defines the schema language to be used <strong>for</strong> validation. The value of this property must be the URI of the<br />

schema language specification. To be compliant with this version of the specification, the implementation must support<br />

the W3C <strong>XML</strong> Schema [http://www.w3.org/2001/<strong>XML</strong>Schema] specification.<br />

When setValidating is set to true and a schema language is set, then the parser must validate against that schema language<br />

only. For example if an application sets the schemaLanguage property to <strong>XML</strong> Schemas then the parser must try to<br />

validate against the <strong>XML</strong> schema only, even if the document has a DOCTYPE declaration that refers to a DTD.<br />

http://java.sun.com/xml/jaxp/properties/schemaSource<br />

The <strong>XML</strong> Schema Recommendation explicitly states that the inclusion of schemaLocation / noNamespaceSchema<br />

Location attributes in an instance document is only a hint; it does not mandate that these attributes must be used to<br />

locate schemas.<br />

The schemaSource property lets the user set the schema(s) to validate against. If the target namespace of a schema<br />

specified using this property matches the target namespace of a schema occurring in schemaLocation attribute, the<br />

schema specified by the user using this property will be used and the instance document’s schemaLocation attribute<br />

will be effectively ignored. However if the target namespace of any schema specified using this property doesn’t match<br />

the target namespace of a schema occurring in the instance document, then the hint specified in the instance document<br />

will be used <strong>for</strong> validation. The acceptable value <strong>for</strong> this property must be one of the following:<br />

• String that points to the URI of the schema<br />

• InputStream with the contents of the schema<br />

• SAX InputSource<br />

• File<br />

• an array of Objects with the contents being one of the types defined above. An array of Objects can be used only<br />

when the schema language has the ability to assemble a schema at runtime. When an array of Objects is passed it<br />

is illegal to have two schemas that share the same namespace.<br />

If no target namespace is defined, then only one schema can be referenced by the property and it must work exactly<br />

the way xsi:noNamespaceSchemaLocation does.<br />

It is illegal to set the schemaSource property if the schemaLanguage property has not been set. In that case, the imple<br />

mentation must throw a SAXNotSupportedException with a detailed message.<br />

18


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

If the schemaSource property is set using a String, the parser must pass the value of the property to the<br />

org.xml.sax.EntityResolver with the publicId set to null.<br />

javax.xml.parsers.DocumentBuilderFactory<br />

The same property strings as described above <strong>for</strong> the SAXParser must be supported by DocumentBuilderFact<br />

ory.setAttribute method.<br />

When setValidating is set to true and a schema language is set then the parser must validate against that schema language<br />

only. For example if an application sets the schema language property to <strong>XML</strong> Schemas the parser must try to validate<br />

against the <strong>XML</strong> schema only, even if the document has a DOCTYPE declaration that refers to a DTD.<br />

It is illegal to set the schemaSource property if the schemaLanguage property has not been set. In that case, the imple<br />

mentation must throw an IllegalArgumentException with a detailed message.<br />

Note: None of the properties will take effect till the setValidating(true) has been called on the SAXParserFactory or<br />

the DocumentBuilderFactory that was used to create the SAXParser or the DocumentBuilder.<br />

The table below shows the results of various configuration scenarios. In all cases, we assume that setValidating(true)<br />

has been called.<br />

Document<br />

DOCTYPE?<br />

no<br />

no<br />

no<br />

yes / no<br />

yes / no<br />

yes / no<br />

has<br />

schema language<br />

property set to<br />

<strong>XML</strong> Schemas?<br />

no<br />

no<br />

no<br />

yes<br />

yes<br />

yes<br />

schema source<br />

property set?<br />

no<br />

no<br />

yes<br />

no<br />

yes<br />

yes<br />

schema location<br />

attribute present<br />

in document?<br />

no<br />

yes<br />

yes / no<br />

yes<br />

no<br />

yes<br />

Document Valid<br />

ated against<br />

error as per <strong>JAXP</strong> N/A<br />

1.1 spec. Must<br />

have a DOCTYPE<br />

declaration when<br />

validation is<br />

turned on.<br />

Error. Schema lan<br />

guage must be set.<br />

Error schema lan<br />

guage must be set.<br />

xml schemas<br />

xml schemas<br />

xml schemas<br />

Schema file used<br />

N/A<br />

N/A<br />

schema files re<br />

ferred to using the<br />

schema location<br />

attributes present<br />

in the instance<br />

document<br />

schema file re<br />

ferred to in the<br />

schemasource<br />

property<br />

schema file re<br />

ferred to in the<br />

schema source<br />

property, if the tar<br />

get namespace<br />

matches. The<br />

schema file re<br />

ferred to in the<br />

19


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

Document<br />

DOCTYPE?<br />

yes<br />

yes<br />

has<br />

schema language<br />

property set to<br />

<strong>XML</strong> Schemas?<br />

no<br />

no<br />

schema source<br />

property set?<br />

no<br />

yes<br />

schema location<br />

attribute present<br />

in document?<br />

yes / no<br />

yes / no<br />

Document Valid<br />

ated against<br />

DTD<br />

Error. Schema<br />

source cannot be<br />

set without setting<br />

the schema lan<br />

guage.<br />

schema location<br />

attribute is ignored<br />

only if the target<br />

namespace<br />

matches<br />

Schema file used<br />

DTD referred to in<br />

the DOCTYPE<br />

N/A<br />

Samples Using the Properties<br />

Sax parser sample:<br />

try {<br />

SAXParserFactory spf = SAXParserFactory.newInstance();<br />

spf.setNamespaceAware(true);<br />

spf.setValidating(true);<br />

SAXParser sp = spf.newSAXParser();<br />

sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",<br />

"http://www.w3.org/2001/<strong>XML</strong>Schema");<br />

sp.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",<br />

"http://www.example.com/Report.xsd");<br />

DefaultHandler dh = new DefaultHandler();<br />

sp.parse("http://www.wombats.com/foo.xml", dh);<br />

} catch(SAXException se) {<br />

se.printStackTrace();<br />

}<br />

DOM parser sample:<br />

try {<br />

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();<br />

dbf.setNamespaceAware(true);<br />

dbf.setValidating(true);<br />

dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",<br />

"http://www.w3.org/2001/<strong>XML</strong>Schema");<br />

dbf.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",<br />

"http://www.example.com/Report.xsd");<br />

DocumentBuilder db = dbf.newDocumentBuilder();<br />

Document doc = db.parse("http://www.wombats.com/foo.xml");<br />

} catch(DOMException de) {<br />

20


Community Draft<br />

Plugability Layer<br />

Community Draft<br />

}<br />

de.printStackTrace();<br />

Recommended Implementation of Properties<br />

It is recommended that parser implementations recognize properties defined in the <strong>for</strong>m of a URI, as above. Such im<br />

plementations avoid conflicts in the use of the feature and property strings among parser implementations. That is also<br />

the way in which SAX 2.0 defines feature and property strings.<br />

21


Community Draft<br />

Community Draft<br />

Chapter 5. Con<strong>for</strong>mance Requirements<br />

This section describes the con<strong>for</strong>mance requirements <strong>for</strong> parser implementations of this specification. Parser imple<br />

mentations that are accessed via the <strong>API</strong>s defined here must implement these constraints, without exception, to provide<br />

a predictable environment <strong>for</strong> application development and deployment.<br />

Note that applications may provide non-con<strong>for</strong>mant implementations that are able to support the plugability mechanism<br />

defined in the specification, however the system default processor must meet the con<strong>for</strong>mance requirements defined<br />

below.<br />

All Implementations of <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Must Support<br />

the Following Specifications:<br />

• Extensible Markup Language (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11], Extensible Markup Language (<strong>XML</strong>)<br />

1.0 (Second Edition) [http://www.w3.org/TR/REC-xml], Extensible Markup Language (<strong>XML</strong>) 1.0 (Second Edition)<br />

Errata [http://www.w3.org/<strong>XML</strong>/xml-V10-2e-errata]<br />

• Namespaces in <strong>XML</strong> 1.1 [http://www.w3.org/TR/xml-names11/], Namespaces in <strong>XML</strong> 1.0<br />

[spec.namespaces-1.0.link;], Namespaces in <strong>XML</strong> 1.0 Errata [spec.namespaces-1.0-errata.link;]<br />

• <strong>XML</strong> Schema Part 1: Structures [http://www.w3.org/TR/xmlschema-1/], <strong>XML</strong> Schema Part 1: Structures Errata<br />

[http://www.w3.org/2001/05/xmlschema-errata#Errata1], <strong>XML</strong> Schema Part 2: Datatypes<br />

[http://www.w3.org/TR/xmlschema-2/], <strong>XML</strong> Schema Part 2: Datatypes Errata<br />

[http://www.w3.org/2001/05/xmlschema-errata#Errata2]<br />

• XSL Trans<strong>for</strong>mations (XSLT) Version 1.0 [http://www.w3.org/TR/xslt], XSL Trans<strong>for</strong>mations (XSLT) Version<br />

1.0 Errata [http://www.w3.org/1999/11/REC-xslt-19991116-errata]<br />

• <strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath], <strong>XML</strong> Path Language (XPath) Version<br />

1.0 Errata [http://www.w3.org/1999/11/REC-xpath-19991116-errata]<br />

• <strong>XML</strong> Inclusions (XInclude) Version 1.0 [http://www.w3.org/TR/xinclude/]<br />

• Document Object Model (DOM) Level 3 Core [http://www.w3.org/TR/DOM-Level-3-Core], Document Object<br />

Model (DOM) Level 3 Load and Save<br />

• Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong> (SAX) 2.0.1 (sax2 r2) [http://www.saxproject.org/], http://www.saxproject.org/?selected=ext<br />

22


Community Draft<br />

Community Draft<br />

Chapter 6. <strong>XML</strong> Inclusions (XInclude)<br />

What is <strong>XML</strong> Inclusions (XInclude)<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> supports XInclude as defined in <strong>XML</strong> Inclusions (XInclude)<br />

Version 1.0 [http://www.w3.org/TR/xinclude/].<br />

XInclude specifies a processing model and syntax <strong>for</strong> general purpose inclusion. Inclusion is accom<br />

plished by merging a number of <strong>XML</strong> in<strong>for</strong>mation sets into a single composite Infoset. Specification<br />

of the <strong>XML</strong> documents (infosets) to be merged and control over the merging process is expressed<br />

in <strong>XML</strong>-friendly syntax (elements, attributes, URI references).<br />

— <strong>XML</strong> Inclusions (XInclude) Version 1.0, Abstract [http://www.w3.org/TR/xinclude/#abstract]<br />

Implementation Required by <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong><br />

<strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong><br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implements <strong>XML</strong> Inclusions (XInclude)<br />

Version 1.0 with the following limitations<br />

• at the time this specification was developed, there was no standard fragment identifier syntax <strong>for</strong> “application/xml”<br />

resources<br />

• supports XPointers using the XPointer Framework and XPointer element() scheme<br />

• no other XPointer schemes or addressing mechanisms are supported and it is an error to use an other XPointer<br />

scheme or addressing mechanism, the error is signaled by throwing a java.lang.Exception <strong>for</strong> DOM processing<br />

and an org.xml.sax.SAXParseException <strong>for</strong> SAX processing<br />

XInclude processing defaults to false. See <strong>Java</strong>doc <strong>for</strong> javax.xml.parsers.DocumentBuilderFactory and<br />

javax.xml.parsers.SAXParserFactory <strong>for</strong> methods to enable/disable/query the state of XInclude processing.<br />

23


Community Draft<br />

Community Draft<br />

Chapter 7. <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> Specification and<br />

Implementation Version In<strong>for</strong>mation<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong><br />

Specification Version In<strong>for</strong>mation<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> specification version in<strong>for</strong>mation is<br />

made available via javax.xml.Version public static final methods<br />

• public static final String javax.xml.Version.getSpecificationTitle()<br />

• public static final String javax.xml.Version.getSpecificationVersion()<br />

• public static final String javax.xml.Version.getSpecificationVendor()<br />

• public static final String javax.xml.Version.getExtensionName()<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong><br />

Implementation Version In<strong>for</strong>mation<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implementation version in<strong>for</strong>mation is<br />

made available via javax.xml.Version public final methods<br />

• public final String javax.xml.Version.getImplementationTitle()<br />

• public final String javax.xml.Version.getImplementationVersion()<br />

• public final String javax.xml.Version.getImplementationVendor()<br />

• public final String javax.xml.Version.getImplementationVendorID()<br />

• public final String javax.xml.Version.getImplementationURL()<br />

Implementations must specify a version service provider class in META-INF/services/javax.xml.Ab<br />

stractVersion. The service provider must extend javax.xml.AbstractVersion.<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong><br />

Full Specification and Implementation Version In<strong>for</strong>m<br />

ation<br />

A toString() method is available in javax.xml.Version that returns the complete <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> specification and implementation version in<strong>for</strong>mation as a String.<br />

24


Community Draft<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong> Specification and Implementa<br />

Community Draft<br />

Implementors must provide a mechanism to easily expose the complete <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong><br />

(<strong>JAXP</strong>) <strong>1.3</strong> specification and implementation version in<strong>for</strong>mation to the developer and user. The developer and user<br />

should not have to write any programs or applications to access such in<strong>for</strong>mation. An example would be a command<br />

that would print the in<strong>for</strong>mation to System.out <strong>for</strong> implementations that have a command line interface.<br />

25


Community Draft<br />

Community Draft<br />

Chapter 8. Package javax.xml.parsers<br />

Provides classes allowing the processing of <strong>XML</strong> documents. Two types of plugable parsers are supported:<br />

• SAX (Simple <strong>API</strong> <strong>for</strong> <strong>XML</strong>)<br />

• DOM (Document Object Model)<br />

Class DocumentBuilder<br />

Synopsis<br />

Defines the <strong>API</strong> to obtain DOM Document instances from an <strong>XML</strong> document. Using this class, an application program<br />

mer can obtain a org.w3c.dom.Document from <strong>XML</strong>.<br />

An instance of this class can be obtained from the DocumentBuilderFactory.newDocumentBuilder [ Method newDoc<br />

umentBuilder()] method. Once an instance of this class is obtained, <strong>XML</strong> can be parsed from a variety of input sources.<br />

These input sources are InputStreams, Files, URLs, and SAX InputSources.<br />

Note that this class reuses several classes from the SAX <strong>API</strong>. This does not require that the implementor of the under<br />

lying DOM implementation use a SAX parser to parse <strong>XML</strong> document into a Document. It merely requires that the<br />

implementation communicate with the application using these existing <strong>API</strong>s.<br />

public DocumentBuilder {<br />

protected DocumentBuilder();<br />

public Document parse(java.io.InputStream is)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public Document parse(java.io.InputStream is,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public Document parse(java.lang.String uri)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public Document parse(java.io.File f)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public Document abstract parse(org.xml.sax.InputSource is)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public boolean abstract isNamespaceAware();<br />

public boolean abstract isValidating();<br />

public void abstract setEntityResolver(org.xml.sax.EntityResolver er);<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler eh);<br />

public Document abstract newDocument();<br />

public DOMImplementation abstract getDOMImplementation();<br />

26


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

public Schema getSchema();<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

public boolean isXIncludeAware();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.23 $, $Date: 2003/12/06 00:21:42 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.parsers.DocumentBuilder<br />

Members<br />

Constructor DocumentBuilder()<br />

protected DocumentBuilder();<br />

Protected constructor<br />

Method getDOMImplementation()<br />

public DOMImplementation abstract getDOMImplementation();<br />

Obtain an instance of a org.w3c.dom.DOMImplementation object.<br />

Method getSchema()<br />

public Schema getSchema();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get a reference to the the javax.xml.validation.Schema being used by the <strong>XML</strong> processor.<br />

If no schema is being used, null is returned.<br />

Method getSecure<strong>Processing</strong>()<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

27


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

See Also javax.xml.parsers.DocumentBuilderFactory.setSecure<strong>Processing</strong> [Method setSecurePro<br />

cessing(javax.xml.Secure<strong>Processing</strong>)]<br />

Get the javax.xml.Secure<strong>Processing</strong> configuration associated with this parser<br />

.<br />

Method isNamespaceAware()<br />

public boolean abstract isNamespaceAware();<br />

Indicates whether or not this parser is configured to understand namespaces.<br />

Method isValidating()<br />

public boolean abstract isValidating();<br />

Indicates whether or not this parser is configured to validate <strong>XML</strong> documents.<br />

Method isXIncludeAware()<br />

public boolean isXIncludeAware();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

See Also javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware [Method setXInclude<br />

Aware(boolean)]<br />

Get the XInclude processing mode <strong>for</strong> this parser.<br />

Method newDocument()<br />

public Document abstract newDocument();<br />

Obtain a new instance of a DOM org.w3c.dom.Document object to build a DOM tree with.<br />

Method parse(File)<br />

public Document parse(java.io.File f)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

28


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Parameters<br />

f<br />

returns<br />

Exceptions<br />

IOException<br />

SAXException<br />

See Also<br />

The file containing the <strong>XML</strong> to parse.<br />

A new DOM Document object.<br />

If any IO errors occur.<br />

If any parse errors occur.<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given file as an <strong>XML</strong> document and return a new DOM org.w3c.dom.Document object. An<br />

IllegalArgumentException is thrown if the File is null null.<br />

Method parse(InputSource)<br />

public Document abstract parse(org.xml.sax.InputSource is)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

returns<br />

InputSource containing the content to be parsed.<br />

A new DOM Document object.<br />

Exceptions<br />

IOException<br />

SAXException<br />

See Also<br />

If any IO errors occur.<br />

If any parse errors occur.<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given input source as an <strong>XML</strong> document and return a new DOM org.w3c.dom.Document object.<br />

An IllegalArgumentException is thrown if the InputSource is null null.<br />

Method parse(InputStream)<br />

public Document parse(java.io.InputStream is)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

returns<br />

InputStream containing the content to be parsed.<br />

Document result of parsing the InputStream<br />

Exceptions<br />

IOException<br />

SAXException<br />

If any IO errors occur.<br />

If any parse errors occur.<br />

29


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given InputStream as an <strong>XML</strong> document and return a new DOM org.w3c.dom.Document<br />

object. An IllegalArgumentException is thrown if the InputStream is null.<br />

Method parse(InputStream, String)<br />

public Document parse(java.io.InputStream is,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

systemId<br />

returns<br />

InputStream containing the content to be parsed.<br />

Provide a base <strong>for</strong> resolving relative URIs.<br />

A new DOM Document object.<br />

Exceptions<br />

IOException<br />

SAXException<br />

See Also<br />

If any IO errors occur.<br />

If any parse errors occur.<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given InputStream as an <strong>XML</strong> document and return a new DOM org.w3c.dom.Document<br />

object. An IllegalArgumentException is thrown if the InputStream is null.<br />

Method parse(String)<br />

public Document parse(java.lang.String uri)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

uri<br />

returns<br />

The location of the content to be parsed.<br />

A new DOM Document object.<br />

Exceptions<br />

IOException<br />

SAXException<br />

See Also<br />

If any IO errors occur.<br />

If any parse errors occur.<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given URI as an <strong>XML</strong> document and return a new DOM org.w3c.dom.Document object. An<br />

IllegalArgumentException is thrown if the URI is null null.<br />

Method setEntityResolver(EntityResolver)<br />

public void abstract setEntityResolver(org.xml.sax.EntityResolver er);<br />

30


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Parameters<br />

er<br />

The EntityResolver to be used to resolve entities present in the <strong>XML</strong> document to be parsed.<br />

Specify the org.xml.sax.EntityResolver to be used to resolve entities present in the <strong>XML</strong> document to be parsed. Setting<br />

this to null will result in the underlying implementation using it's own default implementation and behavior.<br />

Method setErrorHandler(ErrorHandler)<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler eh);<br />

Parameters<br />

eh<br />

The ErrorHandler to be used to resolve entities present in the <strong>XML</strong> document to be parsed.<br />

Specify the org.xml.sax.ErrorHandler to be used to resolve entities present in the <strong>XML</strong> document to be parsed. Setting<br />

this to null will result in the underlying implementation using it's own default implementation and behavior.<br />

Class DocumentBuilderFactory<br />

Synopsis<br />

Defines a factory <strong>API</strong> that enables applications to obtain a parser that produces DOM object trees from <strong>XML</strong> documents.<br />

public DocumentBuilderFactory {<br />

protected DocumentBuilderFactory();<br />

static DocumentBuilderFactory newInstance();<br />

public DocumentBuilder abstract newDocumentBuilder()<br />

throws ParserConfigurationException;<br />

public void setNamespaceAware(boolean awareness);<br />

public void setValidating(boolean validating);<br />

public void setIgnoringElementContentWhitespace(boolean whitespace);<br />

public void setExpandEntityReferences(boolean expandEntityRef);<br />

public void setIgnoringComments(boolean ignoreComments);<br />

public void setCoalescing(boolean coalescing);<br />

public boolean isNamespaceAware();<br />

public boolean isValidating();<br />

public boolean isIgnoringElementContentWhitespace();<br />

public boolean isExpandEntityReferences();<br />

public boolean isIgnoringComments();<br />

31


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

public boolean isCoalescing();<br />

public void abstract setAttribute(java.lang.String name,<br />

java.lang.Object value)<br />

throws java.lang.IllegalArgumentException;<br />

public Object abstract getAttribute(java.lang.String name)<br />

throws java.lang.IllegalArgumentException;<br />

public Schema getSchema();<br />

public void setSchema(javax.xml.validation.Schema schema);<br />

public void setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong> secure<strong>Processing</strong>);<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

public void setXIncludeAware(boolean state);<br />

public boolean isXIncludeAware();<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: <strong>1.3</strong>4 $, $Date: 2003/12/11 18:40:25 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.parsers.DocumentBuilderFactory<br />

Members<br />

Method getAttribute(String)<br />

public Object abstract getAttribute(java.lang.String name)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

name<br />

returns<br />

The name of the attribute.<br />

value The value of the attribute.<br />

Exceptions<br />

IllegalArgumentException<br />

thrown if the underlying implementation doesn't recognize the attribute.<br />

Allows the user to retrieve specific attributes on the underlying implementation.<br />

Method getSchema()<br />

public Schema getSchema();<br />

32


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Gets the javax.xml.validation.Schema object specified through the javax.xml.parsers.DocumentBuilderFactory.setSchema<br />

[ Method setSchema(javax.xml.validation.Schema)] method.<br />

Method getSecure<strong>Processing</strong>()<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get the javax.xml.Secure<strong>Processing</strong> object specified through the javax.xml.parsers.DocumentBuilderFactory.setSe<br />

cure<strong>Processing</strong> [ Method setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong>)] method.<br />

Method isCoalescing()<br />

public boolean isCoalescing();<br />

Indicates whether or not the factory is configured to produce parsers which converts CDATA nodes to Text nodes and<br />

appends it to the adjacent (if any) Text node.<br />

Method isExpandEntityReferences()<br />

public boolean isExpandEntityReferences();<br />

Indicates whether or not the factory is configured to produce parsers which expand entity reference nodes.<br />

Method isIgnoringComments()<br />

public boolean isIgnoringComments();<br />

Indicates whether or not the factory is configured to produce parsers which ignores comments.<br />

Method isIgnoringElementContentWhitespace()<br />

public boolean isIgnoringElementContentWhitespace();<br />

Indicates whether or not the factory is configured to produce parsers which ignore ignorable whitespace in element<br />

content.<br />

Method isNamespaceAware()<br />

public boolean isNamespaceAware();<br />

33


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Indicates whether or not the factory is configured to produce parsers which are namespace aware.<br />

Method isValidating()<br />

public boolean isValidating();<br />

Indicates whether or not the factory is configured to produce parsers which validate the <strong>XML</strong> content during parse.<br />

Method isXIncludeAware()<br />

public boolean isXIncludeAware();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get state of XInclude processing.<br />

Method newDocumentBuilder()<br />

public DocumentBuilder abstract newDocumentBuilder()<br />

throws ParserConfigurationException;<br />

Exceptions<br />

ParserConfigurationExcep<br />

tion<br />

if a DocumentBuilder cannot be created which satisfies the configuration requested.<br />

Creates a new instance of a javax.xml.parsers.DocumentBuilder [ Class DocumentBuilder] using the currently configured<br />

parameters.<br />

Method newInstance()<br />

static DocumentBuilderFactory newInstance();<br />

Exceptions<br />

FactoryConfigurationErr<br />

or<br />

if the implementation is not available or cannot be instantiated.<br />

Obtain a new instance of a DocumentBuilderFactory. This static method creates a new factory instance. This<br />

method uses the following ordered lookup procedure to determine the DocumentBuilderFactory implementation<br />

class to load:<br />

• Use the javax.xml.parsers.DocumentBuilderFactory system property.<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the<br />

key being the system property defined above. The jaxp.properties file is read only once by the <strong>JAXP</strong> implementation<br />

and it's values are then cached <strong>for</strong> future use. If the file does not exist when the first attempt is made to read from<br />

34


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

it, no further attempts are made to check <strong>for</strong> its existence. It is not possible to change the value of any property in<br />

jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> a classname in the file META-INF/services/javax.xml.parsers.DocumentBuild<br />

erFactory in jars available to the runtime.<br />

• Plat<strong>for</strong>m default DocumentBuilderFactory instance.<br />

Once an application has obtained a reference to a DocumentBuilderFactory it can use the factory to configure<br />

and obtain parser instances.<br />

Method setAttribute(String, Object)<br />

public void abstract setAttribute(java.lang.String name,<br />

java.lang.Object value)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

name<br />

value<br />

The name of the attribute.<br />

The value of the attribute.<br />

Exceptions<br />

IllegalArgumentException<br />

thrown if the underlying implementation doesn't recognize the attribute.<br />

Allows the user to set specific attributes on the underlying implementation.<br />

Method setCoalescing(boolean)<br />

public void setCoalescing(boolean coalescing);<br />

Parameters<br />

coalescing<br />

true if the parser produced will convert CDATA nodes to Text nodes and append it to the<br />

adjacent (if any) text node; false otherwise.<br />

Specifies that the parser produced by this code will convert CDATA nodes to Text nodes and append it to the adjacent<br />

(if any) text node. By default the value of this is set to false<br />

Method setExpandEntityReferences(boolean)<br />

public void setExpandEntityReferences(boolean expandEntityRef);<br />

Parameters<br />

expandEntityRef<br />

true if the parser produced will expand entity reference nodes; false otherwise.<br />

Specifies that the parser produced by this code will expand entity reference nodes. By default the value of this is set<br />

to true<br />

35


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method setIgnoringComments(boolean)<br />

public void setIgnoringComments(boolean ignoreComments);<br />

Parameters<br />

ignoreComments<br />

boolean value to ignore comments during processing<br />

Specifies that the parser produced by this code will ignore comments. By default the value of this is set to false .<br />

Method setIgnoringElementContentWhitespace(boolean)<br />

public void setIgnoringElementContentWhitespace(boolean whitespace);<br />

Parameters<br />

whitespace<br />

true if the parser created must eliminate whitespace in the element content when parsing <strong>XML</strong><br />

documents; false otherwise.<br />

Specifies that the parsers created by this factory must eliminate whitespace in element content (sometimes known<br />

loosely as 'ignorable whitespace') when parsing <strong>XML</strong> documents (see <strong>XML</strong> Rec 2.10). Note that only whitespace<br />

which is directly contained within element content that has an element only content model (see <strong>XML</strong> Rec 3.2.1) will<br />

be eliminated. Due to reliance on the content model this setting requires the parser to be in validating mode. By default<br />

the value of this is set to false.<br />

Method setNamespaceAware(boolean)<br />

public void setNamespaceAware(boolean awareness);<br />

Parameters<br />

awareness<br />

true if the parser produced will provide support <strong>for</strong> <strong>XML</strong> namespaces; false otherwise.<br />

Specifies that the parser produced by this code will provide support <strong>for</strong> <strong>XML</strong> namespaces. By default the value of this<br />

is set to false<br />

Method setSchema(Schema)<br />

public void setSchema(javax.xml.validation.Schema schema);<br />

Parameters<br />

schema<br />

Schema to use or null to remove a schema.<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Set the javax.xml.validation.Schema to be used by parsers created from this factory.<br />

36


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

When a javax.xml.validation.Schema is non-null, a parser will use a validator created from it to validate documents<br />

be<strong>for</strong>e it passes in<strong>for</strong>mation down to the application.<br />

When errors are found by the validator, the parser is responsible to report them to the user-specified<br />

org.w3c.dom.DOMErrorHandler, just like any other errors found by the parser itself.<br />

A validator may modify the outcome of a parse (<strong>for</strong> example by adding default values that were missing in documents),<br />

and a parser is responsible to make sure that the application will receive modified DOM trees.<br />

Initialy, null is set as the javax.xml.validation.Schema.<br />

This processing will take effect even if the javax.xml.parsers.DocumentBuilderFactory.isValidating [ Method isValid<br />

ating()] method returns<br />

false<br />

.<br />

It is an error to use the http://java.sun.com/xml/jaxp/properties/schemaSource property and/or<br />

the http://java.sun.com/xml/jaxp/properties/schemaLanguage property in conjunction with a<br />

javax.xml.validation.Schema object. Such configuration will cause a javax.xml.parsers.ParserConfigurationException<br />

[ Exception ParserConfigurationException] exception when the javax.xml.parsers.DocumentBuilderFactory.newDoc<br />

umentBuilder [ Method newDocumentBuilder()] is invoked.<br />

Note <strong>for</strong> implmentors<br />

A parser must be able to work with any javax.xml.validation.Schema implementation.<br />

Method setSecure<strong>Processing</strong>(Secure<strong>Processing</strong>)<br />

public void setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong> secure<strong>Processing</strong>);<br />

Parameters<br />

secure<strong>Processing</strong><br />

If a non-null object is specified, the parser will observe the settings of the specified<br />

javax.xml.Secure<strong>Processing</strong>. Set null to remove the previously set javax.xml.SecurePro<br />

cessing object from this javax.xml.parsers.DocumentBuilderFactory [ Class Document<br />

BuilderFactory].<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Associate the javax.xml.Secure<strong>Processing</strong> configuration <strong>for</strong> this javax.xml.parsers.DocumentBuilderFactory [ Class<br />

DocumentBuilderFactory].<br />

The field is initially set to<br />

37


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

null<br />

, meaning the parsers created by this factory will work in a way specified by the relevant specs.<br />

Method setValidating(boolean)<br />

public void setValidating(boolean validating);<br />

Parameters<br />

validating<br />

true if the parser produced will validate documents as they are parsed; false otherwise.<br />

Specifies that the parser produced by this code will validate documents as they are parsed. By default the value of this<br />

is set to false.<br />

Method setXIncludeAware(boolean)<br />

public void setXIncludeAware(boolean state);<br />

Parameters<br />

state<br />

Set XInclude processing to true or false<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Set state of XInclude processing.<br />

If XInclude markup is found in the document instance, should it be processed as specified in <strong>XML</strong> Inclusions (XInclude)<br />

Version 1.0 [http://www.w3.org/TR/xinclude/].<br />

XInclude processing defaults to false.<br />

Class SAXParser<br />

Defines the <strong>API</strong> that wraps an org.xml.sax.<strong>XML</strong>Reader implementation class. In <strong>JAXP</strong> 1.0, this class wrapped the<br />

org.xml.sax.Parser interface, however this interface was replaced by the org.xml.sax.<strong>XML</strong>Reader. For ease of transition,<br />

this class continues to support the same name and interface as well as supporting new methods. An instance of this<br />

class can be obtained from the javax.xml.parsers.SAXParserFactory.newSAXParser [ Method newSAXParser()]<br />

method. Once an instance of this class is obtained, <strong>XML</strong> can be parsed from a variety of input sources. These input<br />

sources are InputStreams, Files, URLs, and SAX InputSources.<br />

This static method creates a new factory instance based on a system property setting or uses the plat<strong>for</strong>m default if no<br />

property has been defined.<br />

The system property that controls which Factory implementation to create is named "javax.xml.parsers.SAX<br />

ParserFactory". This property names a class that is a concrete subclass of this abstract class. If no property is<br />

defined, a plat<strong>for</strong>m default will be used.<br />

38


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Synopsis<br />

As the content is parsed by the underlying parser, methods of the given org.xml.sax.HandlerBase or the<br />

org.xml.sax.helpers.DefaultHandler are called.<br />

Implementors of this class which wrap an underlaying implementation can consider using the org.xml.sax.help<br />

ers.ParserAdapter class to initially adapt their SAX1 impelemntation to work under this revised class.<br />

public SAXParser {<br />

protected SAXParser();<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.HandlerBase hb,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.helpers.DefaultHandler dh,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.lang.String uri,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.lang.String uri,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.io.File f,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(java.io.File f,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(org.xml.sax.InputSource is,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void parse(org.xml.sax.InputSource is,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

39


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

public Parser abstract getParser()<br />

throws org.xml.sax.SAXException;<br />

public <strong>XML</strong>Reader abstract get<strong>XML</strong>Reader()<br />

throws org.xml.sax.SAXException;<br />

public boolean abstract isNamespaceAware();<br />

public boolean abstract isValidating();<br />

public void abstract setProperty(java.lang.String name,<br />

java.lang.Object value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public Object abstract getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public Schema getSchema();<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

public boolean isXIncludeAware();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.26 $, $Date: 2003/12/06 00:21:41 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.parsers.SAXParser<br />

Members<br />

Constructor SAXParser()<br />

protected SAXParser();<br />

Protected constructor to prevent instaniation. Use javax.xml.parsers.SAXParserFactory.newSAXParser [ Method<br />

newSAXParser()].<br />

Method getParser()<br />

public Parser abstract getParser()<br />

throws org.xml.sax.SAXException;<br />

Exceptions<br />

SAXException<br />

If any SAX errors occur during processing.<br />

Returns the SAX parser that is encapsultated by the implementation of this class.<br />

40


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method getProperty(String)<br />

public Object abstract getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The name of the property to be retrieved.<br />

Value of the requested property.<br />

Exceptions<br />

SAXNotRecognizedEx<br />

ception<br />

SAXNotSupportedExcep<br />

tion<br />

When the underlying <strong>XML</strong>Reader does not recognize the property name.<br />

When the underlying <strong>XML</strong>Reader recognizes the property name but doesn't support the<br />

property.<br />

See Also<br />

org.xml.sax.<strong>XML</strong>Reader.getProperty<br />

Returns the particular property requested <strong>for</strong> in the underlying implementation of org.xml.sax.<strong>XML</strong>Reader.<br />

Method getSchema()<br />

public Schema getSchema();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get a reference to the the javax.xml.validation.Schema being used by the <strong>XML</strong> processor.<br />

If no schema is being used, null is returned.<br />

Method getSecure<strong>Processing</strong>()<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

See Also javax.xml.parsers.SAXParserFactory.setSecure<strong>Processing</strong> [Method setSecurePro<br />

cessing(javax.xml.Secure<strong>Processing</strong>)]<br />

Get the javax.xml.Secure<strong>Processing</strong> configuration associated with this parser<br />

.<br />

41


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method get<strong>XML</strong>Reader()<br />

public <strong>XML</strong>Reader abstract get<strong>XML</strong>Reader()<br />

throws org.xml.sax.SAXException;<br />

Exceptions<br />

SAXException<br />

If any SAX errors occur during processing.<br />

Returns the org.xml.sax.<strong>XML</strong>Reader that is encapsulated by the implementation of this class.<br />

Method isNamespaceAware()<br />

public boolean abstract isNamespaceAware();<br />

Indicates whether or not this parser is configured to understand namespaces.<br />

Method isValidating()<br />

public boolean abstract isValidating();<br />

Indicates whether or not this parser is configured to validate <strong>XML</strong> documents.<br />

Method isXIncludeAware()<br />

public boolean isXIncludeAware();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

See Also<br />

javax.xml.parsers.SAXParserFactory.setXIncludeAware [Method setXIncludeAware(boolean)]<br />

Get the XInclude processing mode <strong>for</strong> this parser.<br />

Method parse(File, DefaultHandler)<br />

public void parse(java.io.File f,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

f<br />

dh<br />

The file containing the <strong>XML</strong> to parse<br />

The SAX DefaultHandler to use.<br />

Exceptions<br />

IllegalArgumentException<br />

If the File object is null.<br />

42


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

IOException<br />

SAXException<br />

See Also<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the file specified as <strong>XML</strong> using the specified org.xml.sax.helpers.DefaultHandler.<br />

Method parse(File, HandlerBase)<br />

public void parse(java.io.File f,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

f<br />

hb<br />

The file containing the <strong>XML</strong> to parse<br />

The SAX HandlerBase to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the File object is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the file specified as <strong>XML</strong> using the specified org.xml.sax.HandlerBase. Use of the DefaultHandler<br />

version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0<br />

Method parse(InputSource, DefaultHandler)<br />

public void parse(org.xml.sax.InputSource is,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

dh<br />

The InputSource containing the content to be parsed.<br />

The SAX DefaultHandler to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the InputSource object is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

43


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Parse the content given org.xml.sax.InputSource as <strong>XML</strong> using the specified org.xml.sax.helpers.DefaultHandler.<br />

Method parse(InputSource, HandlerBase)<br />

public void parse(org.xml.sax.InputSource is,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

hb<br />

The InputSource containing the content to be parsed.<br />

The SAX HandlerBase to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the InputSource object is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content given org.xml.sax.InputSource as <strong>XML</strong> using the specified org.xml.sax.HandlerBase. Use of the<br />

DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in SAX 2.0<br />

Method parse(InputStream, DefaultHandler)<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

dh<br />

InputStream containing the content to be parsed.<br />

The SAX DefaultHandler to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the given InputStream is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given java.io.InputStream instance as <strong>XML</strong> using the specified org.xml.sax.helpers.DefaultHand<br />

ler.<br />

44


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method parse(InputStream, DefaultHandler, String)<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.helpers.DefaultHandler dh,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

dh<br />

systemId<br />

InputStream containing the content to be parsed.<br />

The SAX DefaultHandler to use.<br />

The systemId which is needed <strong>for</strong> resolving relative URIs.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the given InputStream is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

version of this method instead.<br />

Parse the content of the given java.io.InputStream instance as <strong>XML</strong> using the specified org.xml.sax.helpers.DefaultHand<br />

ler.<br />

Method parse(InputStream, HandlerBase)<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

hb<br />

InputStream containing the content to be parsed.<br />

The SAX HandlerBase to use.<br />

Exceptions<br />

IllegalArgumentException<br />

SAXException<br />

IOException<br />

If the given InputStream is null.<br />

If parse produces a SAX error.<br />

If an IO error occurs interacting with the InputStream.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content of the given java.io.InputStream instance as <strong>XML</strong> using the specified org.xml.sax.HandlerBase.<br />

Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in<br />

SAX 2.0.<br />

45


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method parse(InputStream, HandlerBase, String)<br />

public void parse(java.io.InputStream is,<br />

org.xml.sax.HandlerBase hb,<br />

java.lang.String systemId)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

is<br />

hb<br />

systemId<br />

InputStream containing the content to be parsed.<br />

The SAX HandlerBase to use.<br />

The systemId which is needed <strong>for</strong> resolving relative URIs.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the given InputStream is null.<br />

If any IO error occurs interacting with the InputStream.<br />

If any SAX errors occur during processing.<br />

See Also<br />

version of this method instead.<br />

Parse the content of the given java.io.InputStream instance as <strong>XML</strong> using the specified org.xml.sax.HandlerBase.<br />

Use of the DefaultHandler version of this method is recommended as the HandlerBase class has been deprecated in<br />

SAX 2.0.<br />

Method parse(String, DefaultHandler)<br />

public void parse(java.lang.String uri,<br />

org.xml.sax.helpers.DefaultHandler dh)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

uri<br />

dh<br />

The location of the content to be parsed.<br />

The SAX DefaultHandler to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the uri is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content described by the giving Uni<strong>for</strong>m Resource Identifier (URI) as <strong>XML</strong> using the specified<br />

org.xml.sax.helpers.DefaultHandler.<br />

46


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method parse(String, HandlerBase)<br />

public void parse(java.lang.String uri,<br />

org.xml.sax.HandlerBase hb)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

uri<br />

hb<br />

The location of the content to be parsed.<br />

The SAX HandlerBase to use.<br />

Exceptions<br />

IllegalArgumentException<br />

IOException<br />

SAXException<br />

If the uri is null.<br />

If any IO errors occur.<br />

If any SAX errors occur during processing.<br />

See Also<br />

org.xml.sax.DocumentHandler<br />

Parse the content described by the giving Uni<strong>for</strong>m Resource Identifier (URI) as <strong>XML</strong> using the specified<br />

org.xml.sax.HandlerBase. Use of the DefaultHandler version of this method is recommended as the HandlerBase<br />

class has been deprecated in SAX 2.0<br />

Method setProperty(String, Object)<br />

public void abstract setProperty(java.lang.String name,<br />

java.lang.Object value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

value<br />

The name of the property to be set.<br />

The value of the property to be set.<br />

Exceptions<br />

SAXNotRecognizedEx<br />

ception<br />

SAXNotSupportedExcep<br />

tion<br />

When the underlying <strong>XML</strong>Reader does not recognize the property name.<br />

When the underlying <strong>XML</strong>Reader recognizes the property name but doesn't support the<br />

property.<br />

See Also<br />

org.xml.sax.<strong>XML</strong>Reader.setProperty<br />

Sets the particular property in the underlying implementation of org.xml.sax.<strong>XML</strong>Reader. A list of the core features<br />

and properties can be found at http://www.megginson.com/SAX/<strong>Java</strong>/features.html<br />

[http://www.megginson.com/SAX/<strong>Java</strong>/features.html].<br />

47


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Class SAXParserFactory<br />

Synopsis<br />

Defines a factory <strong>API</strong> that enables applications to configure and obtain a SAX based parser to parse <strong>XML</strong> documents.<br />

}<br />

public SAXParserFactory {<br />

protected SAXParserFactory();<br />

static SAXParserFactory newInstance();<br />

public SAXParser abstract newSAXParser()<br />

throws ParserConfigurationException, org.xml.sax.SAXException;<br />

public void setNamespaceAware(boolean awareness);<br />

public void setValidating(boolean validating);<br />

public boolean isNamespaceAware();<br />

public boolean isValidating();<br />

public void abstract setFeature(java.lang.String name,<br />

boolean value)<br />

throws ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax<br />

public boolean abstract getFeature(java.lang.String name)<br />

throws ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax<br />

public Schema getSchema();<br />

public void setSchema(javax.xml.validation.Schema schema);<br />

public void setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong> secure<strong>Processing</strong>);<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

public void setXIncludeAware(boolean state);<br />

public boolean isXIncludeAware();<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: <strong>1.3</strong>3 $, $Date: 2003/12/11 18:40:25 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.parsers.SAXParserFactory<br />

48


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Members<br />

Constructor SAXParserFactory()<br />

protected SAXParserFactory();<br />

Protected constructor to <strong>for</strong>ce use of javax.xml.parsers.SAXParserFactory.newInstance [ Method newInstance()].<br />

Method getFeature(String)<br />

public boolean abstract getFeature(java.lang.String name)<br />

throws ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax<br />

Parameters<br />

name<br />

returns<br />

The name of the property to be retrieved.<br />

Value of the requested property.<br />

Exceptions<br />

ParserConfigurationExcep<br />

tion<br />

SAXNotRecognizedEx<br />

ception<br />

SAXNotSupportedExcep<br />

tion<br />

if a parser cannot be created which satisfies the requested configuration.<br />

When the underlying <strong>XML</strong>Reader does not recognize the property name.<br />

When the underlying <strong>XML</strong>Reader recognizes the property name but doesn't support the<br />

property.<br />

See Also<br />

org.xml.sax.<strong>XML</strong>Reader.getProperty<br />

Returns the particular property requested <strong>for</strong> in the underlying implementation of org.xml.sax.<strong>XML</strong>Reader.<br />

Method getSchema()<br />

public Schema getSchema();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Gets the javax.xml.validation.Schema object specified through the javax.xml.parsers.SAXParserFactory.setSchema [<br />

Method setSchema(javax.xml.validation.Schema)] method.<br />

Method getSecure<strong>Processing</strong>()<br />

public Secure<strong>Processing</strong> getSecure<strong>Processing</strong>();<br />

49


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get the javax.xml.Secure<strong>Processing</strong> object specified through the javax.xml.parsers.SAXParserFactory.setSecurePro<br />

cessing [ Method setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong>)] method.<br />

Method isNamespaceAware()<br />

public boolean isNamespaceAware();<br />

Indicates whether or not the factory is configured to produce parsers which are namespace aware.<br />

Method isValidating()<br />

public boolean isValidating();<br />

Indicates whether or not the factory is configured to produce parsers which validate the <strong>XML</strong> content during parse.<br />

Method isXIncludeAware()<br />

public boolean isXIncludeAware();<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Get state of XInclude processing.<br />

Method newInstance()<br />

static SAXParserFactory newInstance();<br />

Exceptions<br />

FactoryConfigurationErr<br />

or<br />

if the implementation is not available or cannot be instantiated.<br />

Obtain a new instance of a SAXParserFactory. This static method creates a new factory instance This method<br />

uses the following ordered lookup procedure to determine the SAXParserFactory implementation class to load:<br />

• Use the javax.xml.parsers.SAXParserFactory system property.<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the<br />

key being the system property defined above. The jaxp.properties file is read only once by the <strong>JAXP</strong> implementation<br />

and it's values are then cached <strong>for</strong> future use. If the file does not exist when the first attempt is made to read from<br />

50


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

it, no further attempts are made to check <strong>for</strong> its existence. It is not possible to change the value of any property in<br />

jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> a classname in the file META-INF/services/javax.xml.parsers.SAXParserFactory<br />

in jars available to the runtime.<br />

• Plat<strong>for</strong>m default SAXParserFactory instance.<br />

Once an application has obtained a reference to a SAXParserFactory it can use the factory to configure and obtain<br />

parser instances.<br />

Method newSAXParser()<br />

public SAXParser abstract newSAXParser()<br />

throws ParserConfigurationException, org.xml.sax.SAXException;<br />

Exceptions<br />

ParserConfigurationExcep<br />

tion<br />

SAXException<br />

if a parser cannot be created which satisfies the requested configuration.<br />

<strong>for</strong> SAX errors.<br />

Creates a new instance of a SAXParser using the currently configured factory parameters.<br />

Method setFeature(String, boolean)<br />

public void abstract setFeature(java.lang.String name,<br />

boolean value)<br />

throws ParserConfigurationException, org.xml.sax.SAXNotRecognizedException, org.xml.sax<br />

Parameters<br />

name<br />

value<br />

The name of the feature to be set.<br />

The value of the feature to be set.<br />

Exceptions<br />

ParserConfigurationExcep<br />

tion<br />

SAXNotRecognizedEx<br />

ception<br />

SAXNotSupportedExcep<br />

tion<br />

if a parser cannot be created which satisfies the requested configuration.<br />

When the underlying <strong>XML</strong>Reader does not recognize the property name.<br />

When the underlying <strong>XML</strong>Reader recognizes the property name but doesn't support the<br />

property.<br />

See Also<br />

org.xml.sax.<strong>XML</strong>Reader.setFeature<br />

Sets the particular feature in the underlying implementation of org.xml.sax.<strong>XML</strong>Reader. A list of the core features<br />

and properties can be found at http://www.saxproject.org/<br />

51


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method setNamespaceAware(boolean)<br />

public void setNamespaceAware(boolean awareness);<br />

Parameters<br />

awareness<br />

true if the parser produced by this code will provide support <strong>for</strong> <strong>XML</strong> namespaces; false other<br />

wise.<br />

Specifies that the parser produced by this code will provide support <strong>for</strong> <strong>XML</strong> namespaces. By default the value of this<br />

is set to false.<br />

Method setSchema(Schema)<br />

public void setSchema(javax.xml.validation.Schema schema);<br />

Parameters<br />

schema<br />

Schema to use, null to remove a schema.<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Set the javax.xml.validation.Schema to be used by parsers created from this factory.<br />

When a javax.xml.validation.Schema is non-null, a parser will use a validator created from it to validate documents<br />

be<strong>for</strong>e it passes in<strong>for</strong>mation down to the application.<br />

When errors are found by the validator, the parser is responsible to report them to the user-specified org.xml.sax.Er<br />

rorHandler, just like any other errors found by the parser itself.<br />

A validator may modify the SAX event stream (<strong>for</strong> example by adding default values that were missing in documents),<br />

and a parser is responsible to make sure that the application will receive those modified event stream.<br />

Initialy, null is set as the javax.xml.validation.Schema.<br />

This processing will take effect even if the javax.xml.parsers.SAXParserFactory.isValidating [ Method isValidating()]<br />

method returns false.<br />

It is an error to use the http://java.sun.com/xml/jaxp/properties/schemaSource property and/or<br />

the http://java.sun.com/xml/jaxp/properties/schemaLanguage property in conjunction with a<br />

non-null javax.xml.validation.Schema object. Such configuration will cause a javax.xml.parsers.ParserConfigurationEx<br />

ception [ Exception ParserConfigurationException] exception when the javax.xml.parsers.SAXParserFactory.newS<br />

AXParser [ Method newSAXParser()] is invoked.<br />

Note <strong>for</strong> implmentors<br />

A parser must be able to work with any javax.xml.validation.Schema implementation.<br />

52


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Method setSecure<strong>Processing</strong>(Secure<strong>Processing</strong>)<br />

public void setSecure<strong>Processing</strong>(javax.xml.Secure<strong>Processing</strong> secure<strong>Processing</strong>);<br />

Parameters<br />

secure<strong>Processing</strong><br />

If a non-null object is specified, the parser will observe the settings of the specified<br />

javax.xml.Secure<strong>Processing</strong>. Set null to remove the previously set javax.xml.SecurePro<br />

cessing object from this javax.xml.parsers.SAXParserFactory [ Class SAXParserFactory].<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

Associate the javax.xml.Secure<strong>Processing</strong> configuration <strong>for</strong> this SAXParserFactory.<br />

The field is initially set to<br />

null<br />

, meaning the parsers created by this factory will work in a way specified by the relevant specs.<br />

Method setValidating(boolean)<br />

public void setValidating(boolean validating);<br />

Parameters<br />

validating<br />

true if the parser produced by this code will validate documents as they are parsed; false oth<br />

erwise.<br />

Specifies that the parser produced by this code will validate documents as they are parsed. By default the value of this<br />

is set to false.<br />

Method setXIncludeAware(boolean)<br />

public void setXIncludeAware(boolean state);<br />

Parameters<br />

state<br />

Set XInclude processing to true or false<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

For backward compatibility, when implementations <strong>for</strong> earlier versions of <strong>JAXP</strong> is used,<br />

this exception will be thrown.<br />

Since 1.5<br />

53


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Set state of XInclude processing.<br />

If XInclude markup is found in the document instance, should it be processed as specified in <strong>XML</strong> Inclusions (XInclude)<br />

Version 1.0 [http://www.w3.org/TR/xinclude/].<br />

XInclude processing defaults to false.<br />

Exception ParserConfigurationException<br />

Synopsis<br />

Indicates a serious configuration error.<br />

}<br />

public ParserConfigurationException extends Exception {<br />

public ParserConfigurationException();<br />

public ParserConfigurationException(java.lang.String msg);<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.2 $, $Date: 2003/12/06 00:21:41 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.parsers.ParserConfigurationException<br />

Members<br />

Constructor ParserConfigurationException()<br />

public ParserConfigurationException();<br />

Create a new ParserConfigurationException with no detail mesage.<br />

Constructor ParserConfigurationException(String)<br />

public ParserConfigurationException(java.lang.String msg);<br />

Parameters<br />

msg<br />

The error message <strong>for</strong> the exception.<br />

54


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Create a new ParserConfigurationException with the String specified as an error message.<br />

Error FactoryConfigurationError<br />

Synopsis<br />

Thrown when a problem with configuration with the Parser Factories exists. This error will typically be thrown when<br />

the class of a parser factory specified in the system properties cannot be found or instantiated.<br />

}<br />

public FactoryConfigurationError extends Error {<br />

public FactoryConfigurationError();<br />

public FactoryConfigurationError(java.lang.String msg);<br />

public FactoryConfigurationError(java.lang.Exception e);<br />

public FactoryConfigurationError(java.lang.Exception e,<br />

java.lang.String msg);<br />

public String getMessage();<br />

public Exception getException();<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.2 $, $Date: 2003/12/06 00:21:42 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Error<br />

|<br />

javax.xml.parsers.FactoryConfigurationError<br />

Members<br />

Constructor FactoryConfigurationError()<br />

public FactoryConfigurationError();<br />

Create a new FactoryConfigurationError with no detail mesage.<br />

Constructor FactoryConfigurationError(Exception)<br />

public FactoryConfigurationError(java.lang.Exception e);<br />

55


Community Draft<br />

Package javax.xml.parsers<br />

Community Draft<br />

Parameters<br />

eThe exception to be encapsulated in a FactoryConfigurationError.<br />

Create a new FactoryConfigurationError with a given Exception base cause of the error.<br />

Constructor FactoryConfigurationError(Exception, String)<br />

public FactoryConfigurationError(java.lang.Exception e,<br />

java.lang.String msg);<br />

Parameters<br />

e<br />

msg<br />

The exception to be encapsulated in a FactoryConfigurationError<br />

The detail message.<br />

Create a new FactoryConfigurationError with the given Exception base cause and detail message.<br />

Constructor FactoryConfigurationError(String)<br />

public FactoryConfigurationError(java.lang.String msg);<br />

Parameters<br />

msg<br />

The error message <strong>for</strong> the exception.<br />

Create a new FactoryConfigurationError with the String specified as an error message.<br />

Method getException()<br />

public Exception getException();<br />

Return the actual exception (if any) that caused this exception to be raised.<br />

Method getMessage()<br />

public String getMessage();<br />

Return the message (if any) <strong>for</strong> this error . If there is no message <strong>for</strong> the exception and there is an encapsulated exception<br />

then the message of that exception, if it exists will be returned. Else the name of the encapsulated exception will be<br />

returned.<br />

56


Community Draft<br />

Community Draft<br />

Chapter 9. Package javax.xml.trans<strong>for</strong>m<br />

This package defines the generic <strong>API</strong>s <strong>for</strong> processing trans<strong>for</strong>mation instructions, and per<strong>for</strong>ming a trans<strong>for</strong>mation<br />

from source to result. These interfaces have no dependencies on SAX or the DOM standard, and try to make as few<br />

assumptions as possible about the details of the source and result of a trans<strong>for</strong>mation. It achieves this by defining<br />

javax.xml.trans<strong>for</strong>m.Source [ Interface Source] and javax.xml.trans<strong>for</strong>m.Result [ Interface Result] interfaces.<br />

To define concrete classes <strong>for</strong> the user, the <strong>API</strong> defines specializations of the interfaces found at the root level. These<br />

interfaces are found in javax.xml.trans<strong>for</strong>m.sax [ Chapter 11, Package javax.xml.trans<strong>for</strong>m.sax], javax.xml.trans<strong>for</strong>m.dom<br />

[ Chapter 10, Package javax.xml.trans<strong>for</strong>m.dom], and javax.xml.trans<strong>for</strong>m.stream [ Chapter 12, Package<br />

javax.xml.trans<strong>for</strong>m.stream].<br />

Creating Objects<br />

The <strong>API</strong> allows a concrete javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory [ Class Trans<strong>for</strong>merFactory] object to be created<br />

from the static function javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.newInstance [ Method newInstance()].<br />

Specification of Inputs and Outputs<br />

This <strong>API</strong> defines two interface objects called javax.xml.trans<strong>for</strong>m.Source [ Interface Source] and javax.xml.trans<br />

<strong>for</strong>m.Result [ Interface Result]. In order to pass Source and Result objects to the interfaces, concrete classes must be<br />

used. Three concrete representations are defined <strong>for</strong> each of these objects: javax.xml.trans<strong>for</strong>m.stream.StreamSource<br />

[ Class StreamSource] and javax.xml.trans<strong>for</strong>m.stream.StreamResult [ Class StreamResult], javax.xml.trans<strong>for</strong>m.sax.SAX<br />

Source [ Class SAXSource] and javax.xml.trans<strong>for</strong>m.sax.SAXResult [ Class SAXResult], and javax.xml.trans<br />

<strong>for</strong>m.dom.DOMSource [ Class DOMSource] and javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Class DOMResult]. Each<br />

of these objects defines a FEATURE string (which is i the <strong>for</strong>m of a URL), which can be passed into javax.xml.trans<br />

<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] to see if the given type of Source or Result<br />

object is supported. For instance, to test if a DOMSource and a StreamResult is supported, you can apply the following<br />

test.<br />

Trans<strong>for</strong>merFactory tfactory = Trans<strong>for</strong>merFactory.newInstance();<br />

if (tfactory.getFeature(DOMSource.FEATURE) && tfactory.getFeature(StreamResult.FEATURE)) {<br />

...<br />

}<br />

Qualified Name Representation<br />

Namespaces [http://www.w3.org/TR/REC-xml-names] present something of a problem area when dealing with <strong>XML</strong><br />

objects. Qualified Names appear in <strong>XML</strong> markup as prefixed names. But the prefixes themselves do not hold identity.<br />

Rather, it is the URIs that they contextually map to that hold the identity. There<strong>for</strong>e, when passing a Qualified Name<br />

like "xyz:foo" among <strong>Java</strong> programs, one must provide a means to map "xyz" to a namespace.<br />

One solution has been to create a "QName" object that holds the namespace URI, as well as the prefix and local name,<br />

but this is not always an optimal solution, as when, <strong>for</strong> example, you want to use unique strings as keys in a dictionary<br />

57


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

object. Not having a string representation also makes it difficult to specify a namespaced identity outside the context<br />

of an <strong>XML</strong> document.<br />

In order to pass namespaced values to trans<strong>for</strong>mations, <strong>for</strong> instance as a set of properties to the Serializer, this specific<br />

ation defines that a String "qname" object parameter be passed as two-part string, the namespace URI enclosed in curly<br />

braces ({}), followed by the local name. If the qname has a null URI, then the String object only contains the local<br />

name. An application can safely check <strong>for</strong> a non-null URI by testing to see if the first character of the name is a '{'<br />

character.<br />

For example, if a URI and local name were obtained from an element defined with , then the Qualified Name would be "{http://xyz.foo.com/yada/baz.html}foo". Note<br />

that the prefix is lost.<br />

Result Tree Serialization<br />

Serialization of the result tree to a stream can be controlled with the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProp<br />

erties [ Method setOutputProperties(java.util.Properties)] and the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperty<br />

[ Method setOutputProperty(java.lang.String, java.lang.String)] methods. Strings that match the XSLT specification<br />

<strong>for</strong> xsl:output attributes [http://www.w3.org/TR/xslt#output] can be referenced from the javax.xml.trans<strong>for</strong>m.OutputKeys<br />

[ Class OutputKeys] class. Other strings can be specified as well. If the trans<strong>for</strong>mer does not recognize an output key,<br />

a java.lang.IllegalArgumentException is thrown, unless the key name is namespace qualified [#qname-delimiter].<br />

Output key names that are qualified by a namespace are ignored or passed on to the serializer mechanism.<br />

If all that is desired is the simple identity trans<strong>for</strong>mation of a source to a result, then javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer<br />

Factory [ Class Trans<strong>for</strong>merFactory] provides a javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.newTrans<strong>for</strong>mer [ Method<br />

newTrans<strong>for</strong>mer()] method with no arguments. This method creates a Trans<strong>for</strong>mer that effectively copies the source<br />

to the result. This method may be used to create a DOM from SAX events or to create an <strong>XML</strong> or HTML stream from<br />

a DOM or SAX events.<br />

Exceptions and Error Reporting<br />

The trans<strong>for</strong>mation <strong>API</strong> throw three types of specialized exceptions. A javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactoryCon<br />

figurationError [ Error Trans<strong>for</strong>merFactoryConfigurationError] is parallel to the javax.xml.parsers.FactoryConfigura<br />

tionError, and is thrown when a configuration problem with the Trans<strong>for</strong>merFactory exists. This error will typically<br />

be thrown when the trans<strong>for</strong>mation factory class specified with the "javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory" system<br />

property cannot be found or instantiated.<br />

A javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException [ Exception Trans<strong>for</strong>merConfigurationException] may<br />

be thrown if <strong>for</strong> any reason a Trans<strong>for</strong>mer can not be created. A Trans<strong>for</strong>merConfigurationException may be thrown<br />

if there is a syntax error in the trans<strong>for</strong>mation instructions, <strong>for</strong> example when javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFact<br />

ory.newTrans<strong>for</strong>mer [ Method newTrans<strong>for</strong>mer(javax.xml.trans<strong>for</strong>m.Source)] is called.<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [ Exception Trans<strong>for</strong>merException] is a general exception that occurs<br />

during the course of a trans<strong>for</strong>mation. A trans<strong>for</strong>mer exception may wrap another exception, and if any of the<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException.printStackTrace [ Method printStackTrace()] methods are called on it, it<br />

will produce a list of stack dumps, starting from the most recent. The trans<strong>for</strong>mer exception also provides a<br />

javax.xml.trans<strong>for</strong>m.SourceLocator [ Interface SourceLocator] object which indicates where in the source tree or<br />

trans<strong>for</strong>mation instructions the error occurred. javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException.getMessageAndLocation [<br />

Method getMessageAndLocation()] may be called to get an error message with location info, and javax.xml.trans<br />

<strong>for</strong>m.Trans<strong>for</strong>merException.getLocationAsString [ Method getLocationAsString()] may be called to get just the location<br />

string.<br />

Trans<strong>for</strong>mation warnings and errors are sent to an javax.xml.trans<strong>for</strong>m.ErrorListener [ Interface ErrorListener], at<br />

which point the application may decide to report the error or warning, and may decide to throw an Exception <strong>for</strong><br />

58


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

a non-fatal error. The ErrorListener may be set via javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.setErrorListener [<br />

Method setErrorListener(javax.xml.trans<strong>for</strong>m.ErrorListener)] <strong>for</strong> reporting errors that have to do with syntax errors in<br />

the trans<strong>for</strong>mation instructions, or via javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setErrorListener [ Method setErrorListen<br />

er(javax.xml.trans<strong>for</strong>m.ErrorListener)] to report errors that occur during the trans<strong>for</strong>mation. The ErrorListener<br />

on both objects will always be valid and non- null, whether set by the application or a default implementation provided<br />

by the processor. The default implementation provided by the processor will report all warnings and errors to Sys<br />

tem.err and does not throw any Exceptions. Applications are strongly encouraged to register and use ErrorL<br />

isteners that insure proper behavior <strong>for</strong> warnings and errors.<br />

Resolution of URIs within a trans<strong>for</strong>mation<br />

The <strong>API</strong> provides a way <strong>for</strong> URIs referenced from within the stylesheet instructions or within the trans<strong>for</strong>mation to be<br />

resolved by the calling application. This can be done by creating a class that implements the javax.xml.trans<strong>for</strong>m.URI<br />

Resolver [ Interface URIResolver] interface, with its one method, javax.xml.trans<strong>for</strong>m.URIResolver.resolve [ Method<br />

resolve(java.lang.String, java.lang.String)], and use this class to set the URI resolution <strong>for</strong> the trans<strong>for</strong>mation instructions<br />

or trans<strong>for</strong>mation with javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.setURIResolver [ Method setURIResolv<br />

er(javax.xml.trans<strong>for</strong>m.URIResolver)] or javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setURIResolver [ Method setURIResolv<br />

er(javax.xml.trans<strong>for</strong>m.URIResolver)]. The URIResolver.resolve method takes two String arguments, the URI<br />

found in the stylesheet instructions or built as part of the trans<strong>for</strong>mation process, and the base URI in effect when the<br />

URI passed as the first argument was encountered. The returned javax.xml.trans<strong>for</strong>m.Source [ Interface Source] object<br />

must be usable by the trans<strong>for</strong>mer, as specified in its implemented features.<br />

Class OutputKeys<br />

Synopsis<br />

Provides string constants that can be used to set output properties <strong>for</strong> a Trans<strong>for</strong>mer, or to retrieve output properties<br />

from a Trans<strong>for</strong>mer or Templates object.<br />

A properties in this class are read-only.<br />

public OutputKeys {<br />

}<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.OutputKeys<br />

Members<br />

Field CDATA_SECTION_ELEMENTS<br />

static java.lang.String CDATA_SECTION_ELEMENTS ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation.<br />

[http://www.w3.org/TR/xslt#output]<br />

59


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

cdata-section-elements = expanded names expanded names.<br />

cdata-section-elements specifies a whitespace delimited list of the names of elements whose text node children<br />

should be output using CDATA sections.<br />

Field DOCTYPE_PUBLIC<br />

static java.lang.String DOCTYPE_PUBLIC ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

doctype-public = string string.<br />

See the documentation <strong>for</strong> the javax.xml.trans<strong>for</strong>m.OutputKeys.DOCTYPE_SYSTEM [ Field DOCTYPE_SYSTEM]<br />

property <strong>for</strong> a description of what the value of the key should be.<br />

Field DOCTYPE_SYSTEM<br />

static java.lang.String DOCTYPE_SYSTEM ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

doctype-system = string string.<br />

doctype-public specifies the public identifier to be used in the document type declaration.<br />

If the doctype-system property is specified, the xml output method should output a document type declaration imme<br />

diately be<strong>for</strong>e the first element. The name following


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Field INDENT<br />

characters in the range #x21 to #x7E (i.e., printable ASCII characters). The value should either be a charset registered<br />

with the Internet Assigned Numbers Authority [IANA] [#IANA], [RFC2278] [#RFC2278] or start with X-.<br />

static java.lang.String INDENT ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

indent = "yes" | "no".<br />

indent specifies whether the Trans<strong>for</strong>mer may add additional whitespace when outputting the result tree; the value<br />

must be yes or no.<br />

Field MEDIA_TYPE<br />

static java.lang.String MEDIA_TYPE ;<br />

See Also s ection 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

media-type = string string.<br />

media-type specifies the media type (MIME content type) of the data that results from outputting the result tree.<br />

The charset parameter should not be specified explicitly; instead, when the top-level media type is text, a<br />

charset parameter should be added according to the character encoding actually used by the output method.<br />

Field METHOD<br />

static java.lang.String METHOD ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

method = "xml" | "html" | "text" | expanded name expanded name.<br />

The method attribute identifies the overall method that should be used <strong>for</strong> outputting the result tree. Other nonnamespaced<br />

values may be used, such as "xhtml", but, if accepted, the handling of such values is implementation<br />

defined. If any of the method values are not accepted and are not namespace qualified, then javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>mer.setOutputProperty [ Method setOutputProperty(java.lang.String, java.lang.String)] or javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>mer.setOutputProperties [ Method setOutputProperties(java.util.Properties)] will throw a java.lang.IllegalArgu<br />

mentException.<br />

Field OMIT_<strong>XML</strong>_DECLARATION<br />

static java.lang.String OMIT_<strong>XML</strong>_DECLARATION ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

omit-xml-declaration = "yes" | "no".<br />

omit-xml-declaration specifies whether the XSLT processor should output an <strong>XML</strong> declaration; the value<br />

must be yes or no.<br />

61


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Field STANDALONE<br />

static java.lang.String STANDALONE ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

standalone = "yes" | "no".<br />

standalone specifies whether the Trans<strong>for</strong>mer should output a standalone document declaration; the value must<br />

be yes or no.<br />

Field VERSION<br />

static java.lang.String VERSION ;<br />

See Also section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]<br />

version = nmtoken nmtoken.<br />

version specifies the version of the output method.<br />

When the output method is "xml", the version value specifies the version of <strong>XML</strong> to be used <strong>for</strong> outputting the result<br />

tree. The default value <strong>for</strong> the xml output method is 1.0. When the output method is "html", the version value indicates<br />

the version of the HTML. The default value <strong>for</strong> the xml output method is 4.0, which specifies that the result should be<br />

output as HTML con<strong>for</strong>ming to the HTML 4.0 Recommendation [HTML]. If the output method is "text", the version<br />

property is ignored.<br />

Class Trans<strong>for</strong>mer<br />

Synopsis<br />

An instance of this abstract class can trans<strong>for</strong>m a source tree into a result tree.<br />

An instance of this class can be obtained with the Trans<strong>for</strong>merFactory.newTrans<strong>for</strong>mer [ Method newTrans<br />

<strong>for</strong>mer(javax.xml.trans<strong>for</strong>m.Source)] method. This instance may then be used to process <strong>XML</strong> from a variety of sources<br />

and write the trans<strong>for</strong>mation output to a variety of sinks.<br />

An object of this class may not be used in multiple threads running concurrently. Different Trans<strong>for</strong>mers may be used<br />

concurrently by different threads.<br />

A Trans<strong>for</strong>mer may be used multiple times. Parameters and output properties are preserved across trans<strong>for</strong>mations.<br />

public Trans<strong>for</strong>mer {<br />

protected Trans<strong>for</strong>mer();<br />

public void abstract trans<strong>for</strong>m(javax.xml.trans<strong>for</strong>m.Source xmlSource,<br />

javax.xml.trans<strong>for</strong>m.Result outputTarget)<br />

throws Trans<strong>for</strong>merException;<br />

public void abstract setParameter(java.lang.String name,<br />

java.lang.Object value);<br />

62


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

public Object abstract getParameter(java.lang.String name);<br />

public void abstract clearParameters();<br />

public void abstract setURIResolver(javax.xml.trans<strong>for</strong>m.URIResolver resolver);<br />

public URIResolver abstract getURIResolver();<br />

public void abstract setOutputProperties(java.util.Properties o<strong>for</strong>mat);<br />

public Properties abstract getOutputProperties();<br />

public void abstract setOutputProperty(java.lang.String name,<br />

java.lang.String value)<br />

throws java.lang.IllegalArgumentException;<br />

public String abstract getOutputProperty(java.lang.String name)<br />

throws java.lang.IllegalArgumentException;<br />

public void abstract setErrorListener(javax.xml.trans<strong>for</strong>m.ErrorListener listener)<br />

throws java.lang.IllegalArgumentException;<br />

public ErrorListener abstract getErrorListener();<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/06 00:21:44 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer<br />

Members<br />

Constructor Trans<strong>for</strong>mer()<br />

protected Trans<strong>for</strong>mer();<br />

Default constructor is protected on purpose.<br />

Method clearParameters()<br />

public void abstract clearParameters();<br />

Clear all parameters set with setParameter and setParameters.<br />

Method getErrorListener()<br />

public ErrorListener abstract getErrorListener();<br />

Get the error event handler in effect <strong>for</strong> the trans<strong>for</strong>mation.<br />

63


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Method getOutputProperties()<br />

public Properties abstract getOutputProperties();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.OutputKeys [Class OutputKeys], java.util.Properties, XSL Trans<strong>for</strong>mations<br />

(XSLT) Version 1.0 [http://www.w3.org/TR/xslt#output]<br />

Get a copy of the output properties <strong>for</strong> the trans<strong>for</strong>mation.<br />

The properties returned should contain properties set by the user, and properties set by the stylesheet, and these prop<br />

erties are "defaulted" by default properties specified by section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recom<br />

mendation [http://www.w3.org/TR/xslt#output]. The properties that were specifically set by the user or the stylesheet<br />

should be in the base Properties list, while the XSLT default properties that were not specifically set should be the<br />

default Properties list. Thus, getOutputProperties().getProperty(String key) will obtain any property in that was set by<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperty [ Method setOutputProperty(java.lang.String, java.lang.String)],<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperties [ Method setOutputProperties(java.util.Properties)], in the<br />

stylesheet, or the default properties, while getOutputProperties().get(String key) will only retrieve properties that were<br />

explicitly set by javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperty [ Method setOutputProperty(java.lang.String,<br />

java.lang.String)], javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperties [ Method setOutputProperties(java.util.Prop<br />

erties)], or in the stylesheet.<br />

Note that mutation of the Properties object returned will not effect the properties that the trans<strong>for</strong>mation contains.<br />

If any of the argument keys are not recognized and are not namespace qualified, the property will be ignored and not<br />

returned. In other words the behaviour is not orthogonal with setOutputProperties [ Method setOutputProper<br />

ties(java.util.Properties)].<br />

Method getOutputProperty(String)<br />

public String abstract getOutputProperty(java.lang.String name)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

name<br />

returns<br />

A non-null String that specifies an output property name, which may be namespace qualified.<br />

The string value of the output property, or null if no property was found.<br />

Exceptions<br />

IllegalArgumentException<br />

If the property is not supported.<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.OutputKeys [Class OutputKeys]<br />

Get an output property that is in effect <strong>for</strong> the trans<strong>for</strong>mation. The property specified may be a property that was set<br />

with setOutputProperty, or it may be a property specified in the stylesheet.<br />

Method getParameter(String)<br />

public Object abstract getParameter(java.lang.String name);<br />

Parameters<br />

name<br />

of Object to get<br />

64


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

returns<br />

A parameter that has been set with setParameter.<br />

Get a parameter that was explicitly set with setParameter or setParameters.<br />

This method does not return a default parameter value, which cannot be determined until the node context is evaluated<br />

during the trans<strong>for</strong>mation process.<br />

Method getURIResolver()<br />

public URIResolver abstract getURIResolver();<br />

Get an object that will be used to resolve URIs used in document(), etc.<br />

Method setErrorListener(ErrorListener)<br />

public void abstract setErrorListener(javax.xml.trans<strong>for</strong>m.ErrorListener listener)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

listener<br />

The new error listener.<br />

Exceptions<br />

IllegalArgumentException<br />

if listener is null.<br />

Set the error event listener in effect <strong>for</strong> the trans<strong>for</strong>mation.<br />

Method setOutputProperties(Properties)<br />

public void abstract setOutputProperties(java.util.Properties o<strong>for</strong>mat);<br />

Parameters<br />

o<strong>for</strong>mat<br />

See Also<br />

A set of output properties that will be used to override any of the same properties in affect <strong>for</strong> the<br />

trans<strong>for</strong>mation.<br />

javax.xml.trans<strong>for</strong>m.OutputKeys [Class OutputKeys], java.util.Properties<br />

Set the output properties <strong>for</strong> the trans<strong>for</strong>mation. These properties will override properties set in the Templates with<br />

xsl:output.<br />

If argument to this function is null, any properties previously set are removed, and the value will revert to the value<br />

defined in the templates object.<br />

Pass a qualified property key name as a two-part string, the namespace URI enclosed in curly braces ({}), followed<br />

by the local name. If the name has a null URL, the String only contain the local name. An application can safely check<br />

<strong>for</strong> a non-null URI by testing to see if the first character of the name is a '{' character.<br />

For example, if a URI and local name were obtained from an element defined with , then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note<br />

that no prefix is used.<br />

An IllegalArgumentException is thrown if any of the argument keys are not recognized and are not namespace<br />

qualified.<br />

65


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Method setOutputProperty(String, String)<br />

public void abstract setOutputProperty(java.lang.String name,<br />

java.lang.String value)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

name<br />

value<br />

A non-null String that specifies an output property name, which may be namespace qualified.<br />

The non-null string value of the output property.<br />

Exceptions<br />

IllegalArgumentException<br />

If the property is not supported, and is not qualified with a namespace.<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.OutputKeys [Class OutputKeys]<br />

Set an output property that will be in effect <strong>for</strong> the trans<strong>for</strong>mation.<br />

Pass a qualified property name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the<br />

local name. If the name has a null URL, the String only contain the local name. An application can safely check <strong>for</strong> a<br />

non-null URI by testing to see if th first character of the name is a '{' character.<br />

For example, if a URI and local name were obtained from an element defined with , then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note<br />

that no prefix is used.<br />

The Properties object that was passed to javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutputProperties [ Method setOutput<br />

Properties(java.util.Properties)] won't be effected by calling this method.<br />

Method setParameter(String, Object)<br />

public void abstract setParameter(java.lang.String name,<br />

java.lang.Object value);<br />

Parameters<br />

name The name of the parameter, which may begin with a namespace URI in curly braces ({}).<br />

value<br />

The value object. This can be any valid <strong>Java</strong> object. It is up to the processor to provide the proper object<br />

coersion or to simply pass the object on <strong>for</strong> use in an extension.<br />

Add a parameter <strong>for</strong> the trans<strong>for</strong>mation.<br />

Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local<br />

name. If the name has a null URL, the String only contain the local name. An application can safely check <strong>for</strong> a nonnull<br />

URI by testing to see if the first character of the name is a '{' character.<br />

For example, if a URI and local name were obtained from an element defined with , then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note<br />

that no prefix is used.<br />

66


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Method setURIResolver(URIResolver)<br />

public void abstract setURIResolver(javax.xml.trans<strong>for</strong>m.URIResolver resolver);<br />

Parameters<br />

resolver<br />

An object that implements the URIResolver interface, or null.<br />

Set an object that will be used to resolve URIs used in document().<br />

If the resolver argument is null, the URIResolver value will be cleared, and the default behavior will be used.<br />

Method trans<strong>for</strong>m(Source, Result)<br />

public void abstract trans<strong>for</strong>m(javax.xml.trans<strong>for</strong>m.Source xmlSource,<br />

javax.xml.trans<strong>for</strong>m.Result outputTarget)<br />

throws Trans<strong>for</strong>merException;<br />

Parameters<br />

xmlSource<br />

outputTarget<br />

The <strong>XML</strong> input to trans<strong>for</strong>m.<br />

The Result of trans<strong>for</strong>ming the xmlSource.<br />

Exceptions<br />

Trans<strong>for</strong>merException<br />

If an unrecoverable error occurs during the course of the trans<strong>for</strong>mation.<br />

Trans<strong>for</strong>m the <strong>XML</strong> Source to a Result. Specific trans<strong>for</strong>mation behavior is determined by the settings of the<br />

Trans<strong>for</strong>merFactory in effect when the Trans<strong>for</strong>mer was instantiated and any modifications made to the<br />

Trans<strong>for</strong>mer instance.<br />

The Result of trans<strong>for</strong>ming an empty Source is an empty Result.<br />

Empty Source and Result Definitions<br />

Source<br />

javax.xml.trans<strong>for</strong>m.sax.SAXSource<br />

[Class SAXSource]<br />

javax.xml.trans<strong>for</strong>m.dom.DOMSource<br />

[Class DOMSource]<br />

javax.xml.trans<strong>for</strong>m.stream.Stream<br />

Source [Class StreamSource]<br />

Result<br />

Empty Representation<br />

javax.xml.trans<strong>for</strong>m.sax.SAXSource<br />

[Constructor SAXSource()] which uses<br />

org.xml.sax.InputSource to create an<br />

empty SAXSource<br />

javax.xml.trans<strong>for</strong>m.dom.DOMSource<br />

[Constructor DOMSource()] which<br />

uses javax.xml.parsers.DocumentBuild<br />

er#newDocument() to create an empty<br />

DOMSource<br />

javax.xml.trans<strong>for</strong>m.stream.Stream<br />

Source [Constructor StreamSource()]<br />

which uses java.io.InputStream to cre<br />

ate an empty StreamSource<br />

Empty Representation<br />

67


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Empty Source and Result Definitions<br />

javax.xml.trans<strong>for</strong>m.sax.SAXResult<br />

[Class SAXResult]<br />

The SAXResult that was passed as<br />

a parameter is left unchanged. No<br />

methods in SAXResult are invoked.<br />

No methods in any registered Con<br />

tentHandler or LexicalHand<br />

ler are invoked.<br />

javax.xml.trans<strong>for</strong>m.dom.DOMResult The DOMResult that was passed as<br />

[Class DOMResult]<br />

a parameter is left unchanged. No<br />

methods in DOMResult are invoked.<br />

javax.xml.trans<strong>for</strong>m.stream.StreamRes<br />

ult [Class StreamResult]<br />

Class Trans<strong>for</strong>merFactory<br />

Synopsis<br />

The StreamResult that was passed<br />

as a parameter is left unchanged. No<br />

methods in StreamResult are in<br />

voked.<br />

A Trans<strong>for</strong>merFactory instance can be used to create javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer] and<br />

javax.xml.trans<strong>for</strong>m.Templates [ Interface Templates] objects.<br />

The system property that determines which Factory implementation to create is named "javax.xml.trans<br />

<strong>for</strong>m.Trans<strong>for</strong>merFactory". This property names a concrete subclass of the Trans<strong>for</strong>merFactory abstract<br />

class. If the property is not defined, a plat<strong>for</strong>m default is be used.<br />

public Trans<strong>for</strong>merFactory {<br />

protected Trans<strong>for</strong>merFactory();<br />

static Trans<strong>for</strong>merFactory newInstance()<br />

throws Trans<strong>for</strong>merFactoryConfigurationError;<br />

public Trans<strong>for</strong>mer abstract newTrans<strong>for</strong>mer(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

public Trans<strong>for</strong>mer abstract newTrans<strong>for</strong>mer()<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

public Templates abstract newTemplates(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

public Source abstract getAssociatedStylesheet(javax.xml.trans<strong>for</strong>m.Source source,<br />

java.lang.String media,<br />

java.lang.String title,<br />

java.lang.String charset)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

public void abstract setURIResolver(javax.xml.trans<strong>for</strong>m.URIResolver resolver);<br />

public URIResolver abstract getURIResolver();<br />

68


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

public boolean abstract getFeature(java.lang.String name);<br />

public void abstract setAttribute(java.lang.String name,<br />

java.lang.Object value);<br />

public Object abstract getAttribute(java.lang.String name);<br />

public void abstract setErrorListener(javax.xml.trans<strong>for</strong>m.ErrorListener listener);<br />

public ErrorListener abstract getErrorListener();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory<br />

Members<br />

Constructor Trans<strong>for</strong>merFactory()<br />

protected Trans<strong>for</strong>merFactory();<br />

Default constructor is protected on purpose.<br />

Method getAssociatedStylesheet(Source, String, String, String)<br />

public Source abstract getAssociatedStylesheet(javax.xml.trans<strong>for</strong>m.Source source,<br />

java.lang.String media,<br />

java.lang.String title,<br />

java.lang.String charset)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

source<br />

media<br />

title<br />

charset<br />

returns<br />

The <strong>XML</strong> source document.<br />

The media attribute to be matched. May be null, in which case the prefered templates will be used<br />

(i.e. alternate = no).<br />

The value of the title attribute to match. May be null.<br />

The value of the charset attribute to match. May be null.<br />

A Source Object suitable <strong>for</strong> passing to the Trans<strong>for</strong>merFactory.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

An Exception is thrown if an error occurings during parsing of the source.<br />

69


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

See Also<br />

Associating Style Sheets with <strong>XML</strong> documents Version 1.0 [http://www.w3.org/TR/xml-stylesheet/]<br />

Get the stylesheet specification(s) associated with the <strong>XML</strong> Source document via the xml-stylesheet processing in<br />

struction [http://www.w3.org/TR/xml-stylesheet/] that match the given criteria. Note that it is possible to return several<br />

stylesheets, in which case they are applied as if they were a list of imports or cascades in a single stylesheet.<br />

Method getAttribute(String)<br />

public Object abstract getAttribute(java.lang.String name);<br />

Parameters<br />

name<br />

returns<br />

The name of the attribute.<br />

value The value of the attribute.<br />

Allows the user to retrieve specific attributes on the underlying implementation. An IllegalArgumentException<br />

is thrown if the underlying implementation doesn't recognize the attribute.<br />

Method getErrorListener()<br />

public ErrorListener abstract getErrorListener();<br />

Get the error event handler <strong>for</strong> the Trans<strong>for</strong>merFactory.<br />

Method getFeature(String)<br />

public boolean abstract getFeature(java.lang.String name);<br />

Parameters<br />

name<br />

returns<br />

The feature name, which is an absolute URI.<br />

The current state of the feature (true or false).<br />

Look up the value of a feature.<br />

The feature name is any absolute URI.<br />

Method getURIResolver()<br />

public URIResolver abstract getURIResolver();<br />

Get the object that is used by default during the trans<strong>for</strong>mation to resolve URIs used in document(), xsl:import, or<br />

xsl:include.<br />

Method newInstance()<br />

static Trans<strong>for</strong>merFactory newInstance()<br />

throws Trans<strong>for</strong>merFactoryConfigurationError;<br />

70


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Exceptions<br />

Trans<strong>for</strong>merFactoryCon<br />

figurationError<br />

Thrown if the implementation is not available or cannot be instantiated.<br />

Obtain a new instance of a Trans<strong>for</strong>merFactory. This static method creates a new factory instance This method<br />

uses the following ordered lookup procedure to determine the Trans<strong>for</strong>merFactory implementation class to load:<br />

• Use the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory system property.<br />

• Use the properties file "lib/jaxp.properties" in the JRE directory. This configuration file is in standard<br />

java.util.Properties <strong>for</strong>mat and contains the fully qualified name of the implementation class with the<br />

key being the system property defined above. The jaxp.properties file is read only once by the <strong>JAXP</strong> implementation<br />

and it's values are then cached <strong>for</strong> future use. If the file does not exist when the first attempt is made to read from<br />

it, no further attempts are made to check <strong>for</strong> its existence. It is not possible to change the value of any property in<br />

jaxp.properties after it has been read <strong>for</strong> the first time.<br />

• Use the Services <strong>API</strong> (as detailed in the JAR specification), if available, to determine the classname. The Services<br />

<strong>API</strong> will look <strong>for</strong> a classname in the file META-INF/services/javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer<br />

Factory in jars available to the runtime.<br />

• Plat<strong>for</strong>m default Trans<strong>for</strong>merFactory instance.<br />

Once an application has obtained a reference to a Trans<strong>for</strong>merFactory it can use the factory to configure and<br />

obtain parser instances.<br />

Method newTemplates(Source)<br />

public Templates abstract newTemplates(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

source<br />

returns<br />

An object that holds a URL, input stream, etc.<br />

A Templates object capable of being used <strong>for</strong> trans<strong>for</strong>mation purposes, never null.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

May throw this during the parse when it is constructing the Templates object and fails.<br />

Process the Source into a Templates object, which is a a compiled representation of the source. This Templates object<br />

may then be used concurrently across multiple threads. Creating a Templates object allows the Trans<strong>for</strong>merFactory to<br />

do detailed per<strong>for</strong>mance optimization of trans<strong>for</strong>mation instructions, without penalizing runtime trans<strong>for</strong>mation.<br />

Method newTrans<strong>for</strong>mer()<br />

public Trans<strong>for</strong>mer abstract newTrans<strong>for</strong>mer()<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

71


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

Thrown if it is not possible to create a Trans<strong>for</strong>mer instance.<br />

Create a new Trans<strong>for</strong>mer that per<strong>for</strong>ms a copy of the Source to the Result. i.e. the<br />

"identity trans<strong>for</strong>m".<br />

Method newTrans<strong>for</strong>mer(Source)<br />

public Trans<strong>for</strong>mer abstract newTrans<strong>for</strong>mer(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

source<br />

returns<br />

Source of XSLT document used to create Trans<strong>for</strong>mer. Examples of <strong>XML</strong> Sources include<br />

DOMSource [ Class DOMSource], SAXSource [ Class SAXSource], and StreamSource [ Class<br />

StreamSource].<br />

A Trans<strong>for</strong>mer object that may be used to per<strong>for</strong>m a trans<strong>for</strong>mation in a single Thread, never<br />

null.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

Thrown if there are errors when parsing the Source or it is not possible to create a<br />

Trans<strong>for</strong>mer instance.<br />

See Also<br />

XSL Trans<strong>for</strong>mations (XSLT) Version 1.0 [http://www.w3.org/TR/xslt]<br />

Process the Source into a Trans<strong>for</strong>mer Object. The Source is an XSLT document that con<strong>for</strong>ms to XSL<br />

Trans<strong>for</strong>mations (XSLT) Version 1.0 [http://www.w3.org/TR/xslt]. Care must be taken not to use this Trans<strong>for</strong>mer<br />

in multiple Threads running concurrently. Different Trans<strong>for</strong>merFactories can be used concurrently by dif<br />

ferent Threads.<br />

Method setAttribute(String, Object)<br />

public void abstract setAttribute(java.lang.String name,<br />

java.lang.Object value);<br />

Parameters<br />

name<br />

value<br />

The name of the attribute.<br />

The value of the attribute.<br />

Allows the user to set specific attributes on the underlying implementation. An attribute in this context is defined to<br />

be an option that the implementation provides. An IllegalArgumentException is thrown if the underlying<br />

implementation doesn't recognize the attribute.<br />

Method setErrorListener(ErrorListener)<br />

public void abstract setErrorListener(javax.xml.trans<strong>for</strong>m.ErrorListener listener);<br />

72


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Parameters<br />

listener<br />

The new error listener.<br />

Set the error event listener <strong>for</strong> the Trans<strong>for</strong>merFactory, which is used <strong>for</strong> the processing of trans<strong>for</strong>mation instructions,<br />

and not <strong>for</strong> the trans<strong>for</strong>mation itself. An IllegalArgumentException is thrown if the ErrorListener<br />

listener is null.<br />

Method setURIResolver(URIResolver)<br />

public void abstract setURIResolver(javax.xml.trans<strong>for</strong>m.URIResolver resolver);<br />

Parameters<br />

resolver<br />

An object that implements the URIResolver interface, or null.<br />

Set an object that is used by default during the trans<strong>for</strong>mation to resolve URIs used in xsl:import, or xsl:include.<br />

Interface ErrorListener<br />

Synopsis<br />

To provide customized error handling, implement this interface and use the setErrorListener method to register<br />

an instance of the implmentation with the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer]. The Trans<strong>for</strong>mer<br />

then reports all errors and warnings through this interface.<br />

If an application does not register its own custom ErrorListener, the default ErrorListener is used which<br />

reports all warnings and errors to System.err and does not throw any Exceptions. Applications are strongly<br />

encouraged to register and use ErrorListeners that insure proper behavior <strong>for</strong> warnings and errors.<br />

For trans<strong>for</strong>mation errors, a Trans<strong>for</strong>mer must use this interface instead of throwing an Exception: it is up to<br />

the application to decide whether to throw an Exception <strong>for</strong> different types of errors and warnings. Note however<br />

that the Trans<strong>for</strong>mer is not required to continue with the trans<strong>for</strong>mation after a call to javax.xml.trans<strong>for</strong>m.ErrorL<br />

istener.fatalError [ Method fatalError(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException)].<br />

Trans<strong>for</strong>mers may use this mechanism to report <strong>XML</strong> parsing errors as well as trans<strong>for</strong>mation errors.<br />

implements public ErrorListener {<br />

}<br />

public void warning(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

public void error(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

public void fatalError(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.ErrorListener<br />

73


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Members<br />

Method error(Trans<strong>for</strong>merException)<br />

public void error(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

Parameters<br />

exception<br />

The error in<strong>for</strong>mation encapsulated in a trans<strong>for</strong>mer exception.<br />

Exceptions<br />

javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>merException<br />

if the application chooses to discontinue the trans<strong>for</strong>mation.<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [Exception Trans<strong>for</strong>merException]<br />

Receive notification of a recoverable error.<br />

The trans<strong>for</strong>mer must continue to try and provide normal trans<strong>for</strong>mation after invoking this method. It should still be<br />

possible <strong>for</strong> the application to process the document through to the end if no other errors are encountered.<br />

Method fatalError(Trans<strong>for</strong>merException)<br />

public void fatalError(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

Parameters<br />

exception<br />

The error in<strong>for</strong>mation encapsulated in a Trans<strong>for</strong>merException.<br />

Exceptions<br />

javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>merException<br />

if the application chooses to discontinue the trans<strong>for</strong>mation.<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [Exception Trans<strong>for</strong>merException]<br />

Receive notification of a non-recoverable error.<br />

The Trans<strong>for</strong>mer must continue to try and provide normal trans<strong>for</strong>mation after invoking this method. It should still<br />

be possible <strong>for</strong> the application to process the document through to the end if no other errors are encountered, but there<br />

is no guarantee that the output will be useable.<br />

Method warning(Trans<strong>for</strong>merException)<br />

public void warning(javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException exception)<br />

throws Trans<strong>for</strong>merException;<br />

Parameters<br />

exception<br />

The warning in<strong>for</strong>mation encapsulated in a trans<strong>for</strong>mer exception.<br />

74


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Exceptions<br />

javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>merException<br />

if the application chooses to discontinue the trans<strong>for</strong>mation.<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [Exception Trans<strong>for</strong>merException]<br />

Receive notification of a warning.<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer] can use this method to report conditions that are not errors or<br />

fatal errors. The default behaviour is to take no action.<br />

After invoking this method, the Trans<strong>for</strong>mer must continue with the trans<strong>for</strong>mation. It should still be possible <strong>for</strong> the<br />

application to process the document through to the end.<br />

Interface Result<br />

Synopsis<br />

An object that implements this interface contains the in<strong>for</strong>mation needed to build a trans<strong>for</strong>mation result tree.<br />

implements public Result {<br />

}<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.Result<br />

Members<br />

Field PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG<br />

static java.lang.String PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG ;<br />

See Also<br />

disable-output-escaping in XSLT Specification [http://www.w3.org/TR/xslt#disable-output-escaping]<br />

The name of the processing instruction that is sent if the result tree disables output escaping.<br />

Normally, result tree serialization escapes & and < (and possibly other characters) when outputting text nodes. This<br />

ensures that the output is well-<strong>for</strong>med <strong>XML</strong>. However, it is sometimes convenient to be able to produce output that is<br />

almost, but not quite well-<strong>for</strong>med <strong>XML</strong>; <strong>for</strong> example, the output may include ill-<strong>for</strong>med sections that will be trans<strong>for</strong>med<br />

into well-<strong>for</strong>med <strong>XML</strong> by a subsequent non-<strong>XML</strong> aware process. If a processing instruction is sent with this name,<br />

serialization should be output without any escaping.<br />

Result DOM trees may also have PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG and PI_ENABLE_OUTPUT_ESC<strong>API</strong>NG<br />

inserted into the tree.<br />

75


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Field PI_ENABLE_OUTPUT_ESC<strong>API</strong>NG<br />

static java.lang.String PI_ENABLE_OUTPUT_ESC<strong>API</strong>NG ;<br />

See Also<br />

disable-output-escaping in XSLT Specification [http://www.w3.org/TR/xslt#disable-output-escaping]<br />

The name of the processing instruction that is sent if the result tree enables output escaping at some point after having<br />

received a PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG processing instruction.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the system identifier that was set with setSystemId.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URI string.<br />

Set the system identifier <strong>for</strong> this Result.<br />

If the Result is not to be written to a file, the system identifier is optional. The application may still want to provide<br />

one, however, <strong>for</strong> use in error messages and warnings, or to resolve relative output identifiers.<br />

Interface Source<br />

Synopsis<br />

An object that implements this interface contains the in<strong>for</strong>mation needed to act as source input (<strong>XML</strong> source or trans<br />

<strong>for</strong>mation instructions).<br />

implements public Source {<br />

}<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.Source<br />

Members<br />

Method getSystemId()<br />

public String getSystemId();<br />

76


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Get the system identifier that was set with setSystemId.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URL string.<br />

Set the system identifier <strong>for</strong> this Source.<br />

The system identifier is optional if the source does not get its data from a URL, but it may still be useful to provide<br />

one. The application can use a system identifier, <strong>for</strong> example, to resolve relative URIs and to include in error messages<br />

and warnings.<br />

Interface SourceLocator<br />

Synopsis<br />

This interface is primarily <strong>for</strong> the purposes of reporting where an error occurred in the <strong>XML</strong> source or trans<strong>for</strong>mation<br />

instructions.<br />

implements public SourceLocator {<br />

}<br />

public String getPublicId();<br />

public String getSystemId();<br />

public int getLineNumber();<br />

public int getColumnNumber();<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.SourceLocator<br />

Members<br />

Method getColumnNumber()<br />

public int getColumnNumber();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.SourceLocator.getLineNumber [Method getLineNumber()]<br />

Return the character position where the current document event ends.<br />

Warning: The return value from the method is intended only as an approximation <strong>for</strong> the sake of error reporting; it is<br />

not intended to provide sufficient in<strong>for</strong>mation to edit the character content of the original <strong>XML</strong> document.<br />

The return value is an approximation of the column number in the document entity or external parsed entity where the<br />

markup that triggered the event appears.<br />

77


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Method getLineNumber()<br />

public int getLineNumber();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.SourceLocator.getColumnNumber [Method getColumnNumber()]<br />

Return the line number where the current document event ends.<br />

Warning: The return value from the method is intended only as an approximation <strong>for</strong> the sake of error reporting; it is<br />

not intended to provide sufficient in<strong>for</strong>mation to edit the character content of the original <strong>XML</strong> document.<br />

The return value is an approximation of the line number in the document entity or external parsed entity where the<br />

markup that triggered the event appears.<br />

Method getPublicId()<br />

public String getPublicId();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.SourceLocator.getSystemId [Method getSystemId()]<br />

Return the public identifier <strong>for</strong> the current document event.<br />

The return value is the public identifier of the document entity or of the external parsed entity in which the markup<br />

that triggered the event appears.<br />

Method getSystemId()<br />

public String getSystemId();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.SourceLocator.getPublicId [Method getPublicId()]<br />

Return the system identifier <strong>for</strong> the current document event.<br />

The return value is the system identifier of the document entity or of the external parsed entity in which the markup<br />

that triggered the event appears.<br />

If the system identifier is a URL, the parser must resolve it fully be<strong>for</strong>e passing it to the application.<br />

Interface Templates<br />

Synopsis<br />

An object that implements this interface is the runtime representation of processed trans<strong>for</strong>mation instructions.<br />

Templates must be threadsafe <strong>for</strong> a given instance over multiple threads running concurrently, and may be used multiple<br />

times in a given session.<br />

implements public Templates {<br />

public Trans<strong>for</strong>mer newTrans<strong>for</strong>mer()<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

public Properties getOutputProperties();<br />

78


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

}<br />

Members<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.Templates<br />

Method getOutputProperties()<br />

public Properties getOutputProperties();<br />

Get the static properties <strong>for</strong> xsl:output. The object returned will be a clone of the internal values. Accordingly, it can<br />

be mutated without mutating the Templates object, and then handed in to javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.setOutput<br />

Properties [ Method setOutputProperties(java.util.Properties)].<br />

The properties returned should contain properties set by the stylesheet, and these properties are "defaulted" by default<br />

properties specified by section 16 of the XSL Trans<strong>for</strong>mations (XSLT) W3C Recommendation<br />

[http://www.w3.org/TR/xslt#output]. The properties that were specifically set by the stylesheet should be in the base<br />

Properties list, while the XSLT default properties that were not specifically set should be in the "default" Properties<br />

list. Thus, getOutputProperties().getProperty(String key) will obtain any property in that was set by the stylesheet, or<br />

the default properties, while getOutputProperties().get(String key) will only retrieve properties that were explicitly set<br />

in the stylesheet.<br />

For XSLT, Attribute Value Templates [http://www.w3.org/TR/xslt#attribute-value-templates] attribute values will be<br />

returned unexpanded (since there is no context at this point). The namespace prefixes inside Attribute Value Templates<br />

will be unexpanded, so that they remain valid XPath values. (For XSLT 1.0, this is not a problem since Attribute Value<br />

Templates are not allowed <strong>for</strong> xsl:output attributes. However, the will be allowed in versions after 1.1.)<br />

Method newTrans<strong>for</strong>mer()<br />

public Trans<strong>for</strong>mer newTrans<strong>for</strong>mer()<br />

throws Trans<strong>for</strong>merConfigurationException;<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

if a Trans<strong>for</strong>mer can not be created.<br />

Create a new trans<strong>for</strong>mation context <strong>for</strong> this Templates object.<br />

Interface URIResolver<br />

Synopsis<br />

An object that implements this interface that can be called by the processor to turn a URI used in document(), xsl:import,<br />

or xsl:include into a Source object.<br />

implements public URIResolver {<br />

public Source resolve(java.lang.String href,<br />

java.lang.String base)<br />

throws Trans<strong>for</strong>merException;<br />

79


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

}<br />

Members<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.URIResolver<br />

Method resolve(String, String)<br />

public Source resolve(java.lang.String href,<br />

java.lang.String base)<br />

throws Trans<strong>for</strong>merException;<br />

Parameters<br />

href<br />

base<br />

returns<br />

An href attribute, which may be relative or absolute.<br />

The base URI in effect when the href attribute was encountered.<br />

A Source object, or null if the href cannot be resolved, and the processor should try to resolve the<br />

URI itself.<br />

Exceptions<br />

Trans<strong>for</strong>merException<br />

if an error occurs when trying to resolve the URI.<br />

Called by the processor when it encounters an xsl:include, xsl:import, or document() function.<br />

Exception Trans<strong>for</strong>merConfigurationException<br />

Synopsis<br />

Indicates a serious configuration error.<br />

}<br />

public Trans<strong>for</strong>merConfigurationException extends Trans<strong>for</strong>merException {<br />

public Trans<strong>for</strong>merConfigurationException();<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String msg);<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.Throwable e);<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String msg,<br />

java.lang.Throwable e);<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator);<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator,<br />

java.lang.Throwable e);<br />

80


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Members<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException<br />

Constructor Trans<strong>for</strong>merConfigurationException()<br />

public Trans<strong>for</strong>merConfigurationException();<br />

Create a new Trans<strong>for</strong>merConfigurationException with no detail mesage.<br />

Constructor Trans<strong>for</strong>merConfigurationException(String)<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String msg);<br />

Parameters<br />

msg<br />

The error message <strong>for</strong> the exception.<br />

Create a new Trans<strong>for</strong>merConfigurationException with the String specified as an error message.<br />

Constructor Trans<strong>for</strong>merConfigurationException(String, SourceLocator)<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator);<br />

Parameters<br />

message<br />

locator<br />

The error or warning message.<br />

The locator object <strong>for</strong> the error or warning.<br />

Create a new Trans<strong>for</strong>merConfigurationException from a message and a Locator.<br />

This constructor is especially useful when an application is creating its own exception from within a DocumentHandler<br />

callback.<br />

81


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Constructor Trans<strong>for</strong>merConfigurationException(String, SourceLocator,<br />

Throwable)<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator,<br />

java.lang.Throwable e);<br />

Parameters<br />

message<br />

locator<br />

e<br />

The error or warning message, or null to use the message from the embedded exception.<br />

The locator object <strong>for</strong> the error or warning.<br />

Any exception.<br />

Wrap an existing exception in a Trans<strong>for</strong>merConfigurationException.<br />

Constructor Trans<strong>for</strong>merConfigurationException(String, Throwable)<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.String msg,<br />

java.lang.Throwable e);<br />

Parameters<br />

e<br />

msg<br />

The exception to be encapsulated in a Trans<strong>for</strong>merConfigurationException<br />

The detail message.<br />

Create a new Trans<strong>for</strong>merConfigurationException with the given Exception base cause and detail<br />

message.<br />

Constructor Trans<strong>for</strong>merConfigurationException(Throwable)<br />

public Trans<strong>for</strong>merConfigurationException(java.lang.Throwable e);<br />

Parameters<br />

eThe exception to be encapsulated in a Trans<strong>for</strong>merConfigurationException.<br />

Create a new Trans<strong>for</strong>merConfigurationException with a given Exception base cause of the error.<br />

Exception Trans<strong>for</strong>merException<br />

Synopsis<br />

This class specifies an exceptional condition that occured during the trans<strong>for</strong>mation process.<br />

public Trans<strong>for</strong>merException extends Exception {<br />

public Trans<strong>for</strong>merException(java.lang.String message);<br />

public Trans<strong>for</strong>merException(java.lang.Throwable e);<br />

82


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

java.lang.Throwable e);<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator);<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator,<br />

java.lang.Throwable e);<br />

public SourceLocator getLocator();<br />

public void setLocator(javax.xml.trans<strong>for</strong>m.SourceLocator location);<br />

public Throwable getException();<br />

public Throwable getCause();<br />

public Throwable initCause(java.lang.Throwable cause);<br />

public String getMessageAndLocation();<br />

public String getLocationAsString();<br />

public void printStackTrace();<br />

public void printStackTrace(java.io.PrintStream s);<br />

public void printStackTrace(java.io.PrintWriter s);<br />

}<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException<br />

Members<br />

Constructor Trans<strong>for</strong>merException(String)<br />

public Trans<strong>for</strong>merException(java.lang.String message);<br />

Parameters<br />

message<br />

The error or warning message.<br />

Create a new Trans<strong>for</strong>merException.<br />

83


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Constructor Trans<strong>for</strong>merException(String, SourceLocator)<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator);<br />

Parameters<br />

message<br />

locator<br />

The error or warning message.<br />

The locator object <strong>for</strong> the error or warning.<br />

Create a new Trans<strong>for</strong>merException from a message and a Locator.<br />

This constructor is especially useful when an application is creating its own exception from within a DocumentHandler<br />

callback.<br />

Constructor Trans<strong>for</strong>merException(String, SourceLocator, Throwable)<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

javax.xml.trans<strong>for</strong>m.SourceLocator locator,<br />

java.lang.Throwable e);<br />

Parameters<br />

message<br />

locator<br />

e<br />

The error or warning message, or null to use the message from the embedded exception.<br />

The locator object <strong>for</strong> the error or warning.<br />

Any exception<br />

Wrap an existing exception in a Trans<strong>for</strong>merException.<br />

Constructor Trans<strong>for</strong>merException(String, Throwable)<br />

public Trans<strong>for</strong>merException(java.lang.String message,<br />

java.lang.Throwable e);<br />

Parameters<br />

message<br />

e<br />

The error or warning message, or null to use the message from the embedded exception.<br />

Any exception<br />

Wrap an existing exception in a Trans<strong>for</strong>merException.<br />

This is used <strong>for</strong> throwing processor exceptions be<strong>for</strong>e the processing has started.<br />

Constructor Trans<strong>for</strong>merException(Throwable)<br />

public Trans<strong>for</strong>merException(java.lang.Throwable e);<br />

Parameters<br />

eThe exception to be wrapped.<br />

84


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Create a new Trans<strong>for</strong>merException wrapping an existing exception.<br />

Method getCause()<br />

public Throwable getCause();<br />

Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that<br />

caused this throwable to get thrown.)<br />

Method getException()<br />

public Throwable getException();<br />

See Also<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException.getCause [Method getCause()]<br />

This method retrieves an exception that this exception wraps.<br />

Method getLocationAsString()<br />

public String getLocationAsString();<br />

Get the location in<strong>for</strong>mation as a string.<br />

Method getLocator()<br />

public SourceLocator getLocator();<br />

Method getLocator retrieves an instance of a SourceLocator object that specifies where an error occured.<br />

Method getMessageAndLocation()<br />

public String getMessageAndLocation();<br />

Get the error message with location in<strong>for</strong>mation appended.<br />

Method initCause(Throwable)<br />

public Throwable initCause(java.lang.Throwable cause);<br />

Parameters<br />

cause<br />

the cause (which is saved <strong>for</strong> later retrieval by the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException.getCause<br />

[ Method getCause()] method). (A<br />

null<br />

value is permitted, and indicates that the cause is nonexistent or unknown.)<br />

returns<br />

a reference to this Throwable instance.<br />

Exceptions<br />

IllegalArgumentException<br />

if cause is this throwable. (A throwable cannot be its own cause.)<br />

85


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

IllegalStateException<br />

if this throwable was created with javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [ Construct<br />

or Trans<strong>for</strong>merException(java.lang.Throwable)] or javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merEx<br />

ception [ Constructor Trans<strong>for</strong>merException(java.lang.String, java.lang.Throwable)], or<br />

this method has already been called on this throwable.<br />

Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to<br />

get thrown.)<br />

This method can be called at most once. It is generally called from within the constructor, or immediately after creating<br />

the throwable. If this throwable was created with javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [ Constructor Trans<strong>for</strong>mer<br />

Exception(java.lang.Throwable)] or javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException [ Constructor Trans<strong>for</strong>merExcep<br />

tion(java.lang.String, java.lang.Throwable)], this method cannot be called even once.<br />

Method printStackTrace()<br />

public void printStackTrace();<br />

Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as<br />

this object.<br />

Method printStackTrace(PrintStream)<br />

public void printStackTrace(java.io.PrintStream s);<br />

Parameters<br />

sThe stream where the dump will be sent to.<br />

Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as<br />

this object.<br />

Method printStackTrace(PrintWriter)<br />

public void printStackTrace(java.io.PrintWriter s);<br />

Parameters<br />

sThe writer where the dump will be sent to.<br />

Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as<br />

this object.<br />

Method setLocator(SourceLocator)<br />

public void setLocator(javax.xml.trans<strong>for</strong>m.SourceLocator location);<br />

Parameters<br />

location<br />

A SourceLocator object, or null to clear the location.<br />

Method setLocator sets an instance of a SourceLocator object that specifies where an error occured.<br />

86


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Error Trans<strong>for</strong>merFactoryConfigurationError<br />

Synopsis<br />

Thrown when a problem with configuration with the Trans<strong>for</strong>mer Factories exists. This error will typically be thrown<br />

when the class of a trans<strong>for</strong>mation factory specified in the system properties cannot be found or instantiated.<br />

}<br />

public Trans<strong>for</strong>merFactoryConfigurationError extends Error {<br />

public Trans<strong>for</strong>merFactoryConfigurationError();<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.String msg);<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.Exception e);<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.Exception e,<br />

java.lang.String msg);<br />

public String getMessage();<br />

public Exception getException();<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Error<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactoryConfigurationError<br />

Members<br />

Constructor Trans<strong>for</strong>merFactoryConfigurationError()<br />

public Trans<strong>for</strong>merFactoryConfigurationError();<br />

Create a new Trans<strong>for</strong>merFactoryConfigurationError with no detail mesage.<br />

Constructor Trans<strong>for</strong>merFactoryConfigurationError(Exception)<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.Exception e);<br />

Parameters<br />

eThe exception to be encapsulated in a Trans<strong>for</strong>merFactoryConfigurationError.<br />

Create a new Trans<strong>for</strong>merFactoryConfigurationError with a given Exception base cause of the error.<br />

87


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m<br />

Community Draft<br />

Constructor Trans<strong>for</strong>merFactoryConfigurationError(Exception, String)<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.Exception e,<br />

java.lang.String msg);<br />

Parameters<br />

e<br />

msg<br />

The exception to be encapsulated in a Trans<strong>for</strong>merFactoryConfigurationError<br />

The detail message.<br />

Create a new Trans<strong>for</strong>merFactoryConfigurationError with the given Exception base cause and detail<br />

message.<br />

Constructor Trans<strong>for</strong>merFactoryConfigurationError(String)<br />

public Trans<strong>for</strong>merFactoryConfigurationError(java.lang.String msg);<br />

Parameters<br />

msg<br />

The error message <strong>for</strong> the exception.<br />

Create a new Trans<strong>for</strong>merFactoryConfigurationError with the String specified as an error message.<br />

Method getException()<br />

public Exception getException();<br />

Return the actual exception (if any) that caused this exception to be raised.<br />

Method getMessage()<br />

public String getMessage();<br />

Return the message (if any) <strong>for</strong> this error . If there is no message <strong>for</strong> the exception and there is an encapsulated exception<br />

then the message of that exception will be returned.<br />

88


Community Draft<br />

Community Draft<br />

C h a p t e r 1 0 . P a c k a g e<br />

javax.xml.trans<strong>for</strong>m.dom<br />

This package implements DOM-specific trans<strong>for</strong>mation <strong>API</strong>s.<br />

The javax.xml.trans<strong>for</strong>m.dom.DOMSource [ Class DOMSource] class allows the client of the implementation of this<br />

<strong>API</strong> to specify a DOM org.w3c.dom.Node as the source of the input tree. The model of how the Trans<strong>for</strong>mer deals<br />

with the DOM tree in terms of mismatches with the XSLT data model [http://www.w3.org/TR/xslt#data-model] or<br />

other data models is beyond the scope of this document. Any of the nodes derived from org.w3c.dom.Node are legal<br />

input.<br />

The javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Class DOMResult] class allows a org.w3c.dom.Node to be specified to<br />

which result DOM nodes will be appended. If an output node is not specified, the trans<strong>for</strong>mer will use<br />

javax.xml.parsers.DocumentBuilder#newDocument to create an output org.w3c.dom.Document node. If a node is<br />

specified, it should be one of the following: org.w3c.dom.Document, org.w3c.dom.Element, or org.w3c.dom.Document<br />

Fragment. Specification of any other node type is implementation dependent and undefined by this <strong>API</strong>. If the result<br />

is a org.w3c.dom.Document, the output of the trans<strong>for</strong>mation must have a single element root to set as the document<br />

element.<br />

The javax.xml.trans<strong>for</strong>m.dom.DOMLocator [ Interface DOMLocator] node may be passed to javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>merException [ Exception Trans<strong>for</strong>merException] objects, and retrieved by trying to cast the result of the<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merException.getLocator [ Method getLocator()] method. The implementation has no<br />

responsibility to use a DOMLocator instead of a javax.xml.trans<strong>for</strong>m.SourceLocator [ Interface SourceLocator] (though<br />

line numbers and the like do not make much sense <strong>for</strong> a DOM), so the result of getLocator must always be tested with<br />

an instanceof.<br />

Class DOMResult<br />

Synopsis<br />

Acts as a holder <strong>for</strong> a trans<strong>for</strong>mation result tree in the <strong>for</strong>m of a Document Object Model (DOM) tree.<br />

If no output DOM source is set, the trans<strong>for</strong>mation will create a Document node as the holder <strong>for</strong> the result of the<br />

trans<strong>for</strong>mation, which may be retrieved with javax.xml.trans<strong>for</strong>m.dom.DOMResult.getNode [ Method getNode()].<br />

public DOMResultimplements Result {<br />

public DOMResult();<br />

public DOMResult(org.w3c.dom.Node node);<br />

public DOMResult(org.w3c.dom.Node node,<br />

java.lang.String systemId);<br />

public DOMResult(org.w3c.dom.Node node,<br />

org.w3c.dom.Node nextSibling);<br />

public DOMResult(org.w3c.dom.Node node,<br />

org.w3c.dom.Node nextSibling,<br />

java.lang.String systemId);<br />

89


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

public void setNode(org.w3c.dom.Node node);<br />

public Node getNode();<br />

public void setNextSibling(org.w3c.dom.Node nextSibling);<br />

public Node getNextSibling();<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.4 $, $Date: 2003/12/12 03:56:54 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.dom.DOMResult<br />

Members<br />

Constructor DOMResult()<br />

public DOMResult();<br />

Zero-argument default constructor.<br />

node, siblingNode and systemId will be set to null.<br />

Constructor DOMResult(Node)<br />

public DOMResult(org.w3c.dom.Node node);<br />

Parameters<br />

node<br />

The DOM node that will contain the result tree.<br />

Use a DOM node to create a new output target.<br />

In practice, the node should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment node, or a<br />

org.w3c.dom.Element node. In other words, a node that accepts children.<br />

siblingNode and systemId will be set to null.<br />

Constructor DOMResult(Node, Node)<br />

public DOMResult(org.w3c.dom.Node node,<br />

org.w3c.dom.Node nextSibling);<br />

90


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

Parameters<br />

node<br />

nextSibling<br />

Exceptions<br />

IllegalArgumentException<br />

IllegalArgumentException<br />

Since 1.5<br />

The DOM node that will contain the result tree.<br />

The child node where the result nodes should be inserted be<strong>for</strong>e.<br />

If nextSibling is not a sibling of node.<br />

If node is null and nextSibling is not null.<br />

Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted<br />

be<strong>for</strong>e.<br />

In practice, node and nextSibling should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment<br />

node, or a org.w3c.dom.Element node. In other words, a node that accepts children.<br />

Use nextSibling to specify the child node where the result nodes should be inserted be<strong>for</strong>e. If nextSibling is<br />

not a sibling of node, then an IllegalArgumentException is thrown. If node is null and nextSibling<br />

is not null, then an IllegalArgumentException is thrown. If nextSibling is null, then the behavior is<br />

the same as calling javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node)], i.e. append<br />

the result nodes as the last child of the specified node.<br />

systemId will be set to null.<br />

Constructor DOMResult(Node, Node, String)<br />

public DOMResult(org.w3c.dom.Node node,<br />

org.w3c.dom.Node nextSibling,<br />

java.lang.String systemId);<br />

Parameters<br />

node<br />

nextSibling<br />

systemId<br />

The DOM node that will contain the result tree.<br />

The child node where the result nodes should be inserted be<strong>for</strong>e.<br />

The system identifier which may be used in association with this node.<br />

Exceptions<br />

IllegalArgumentException<br />

IllegalArgumentException<br />

If nextSibling is not a sibling of node.<br />

If node is null and nextSibling is not null.<br />

Since 1.5<br />

Use a DOM node to create a new output target specifying the child node where the result nodes should be inserted<br />

be<strong>for</strong>e and the specified System ID.<br />

In practice, node and nextSibling should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment<br />

node, or a org.w3c.dom.Element node. In other words, a node that accepts children.<br />

91


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

Use nextSibling to specify the child node where the result nodes should be inserted be<strong>for</strong>e. If nextSibling is<br />

not a sibling of node, then an IllegalArgumentException is thrown. If node is null and nextSibling<br />

is not null, then an IllegalArgumentException is thrown. If nextSibling is null, then the behavior is<br />

the same as calling javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node,<br />

java.lang.String)], i.e. append the result nodes as the last child of the specified node and use the specified System ID.<br />

Constructor DOMResult(Node, String)<br />

public DOMResult(org.w3c.dom.Node node,<br />

java.lang.String systemId);<br />

Parameters<br />

node<br />

systemId<br />

The DOM node that will contain the result tree.<br />

The system identifier which may be used in association with this node.<br />

Use a DOM node to create a new output target with the specified System ID.<br />

In practice, the node should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment node, or a<br />

org.w3c.dom.Element node. In other words, a node that accepts children.<br />

siblingNode will be set to null.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when<br />

passed this value as an argument, the Trans<strong>for</strong>mer supports Result output of this type.<br />

Method getNextSibling()<br />

public Node getNextSibling();<br />

Since 1.5<br />

Get the child node where the result nodes will be inserted be<strong>for</strong>e.<br />

If no node was set via javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node,<br />

org.w3c.dom.Node)], javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node,<br />

org.w3c.dom.Node, java.lang.String)] or javax.xml.trans<strong>for</strong>m.dom.DOMResult.setNextSibling [ Method setNextSib<br />

ling(org.w3c.dom.Node)], then null will be returned.<br />

Method getNode()<br />

public Node getNode();<br />

Get the node that will contain the result DOM tree.<br />

If no node was set via javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node)],<br />

javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node, java.lang.String)],<br />

javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node, org.w3c.dom.Node)],<br />

javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node, org.w3c.dom.Node,<br />

java.lang.String)] or javax.xml.trans<strong>for</strong>m.dom.DOMResult.setNode [ Method setNode(org.w3c.dom.Node)], then the<br />

92


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

node will be set by the trans<strong>for</strong>mation, and may be obtained from this method once the trans<strong>for</strong>mation is complete.<br />

Calling this method be<strong>for</strong>e the trans<strong>for</strong>mation will return null.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the System Identifier.<br />

If no System ID was set via javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node,<br />

java.lang.String)], javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node,<br />

org.w3c.dom.Node, java.lang.String)] or javax.xml.trans<strong>for</strong>m.dom.DOMResult.setSystemId [ Method setSys<br />

temId(java.lang.String)], then null will be returned.<br />

Method setNextSibling(Node)<br />

public void setNextSibling(org.w3c.dom.Node nextSibling);<br />

Parameters<br />

nextSibling<br />

The child node where the result nodes will be inserted be<strong>for</strong>e.<br />

Exceptions<br />

IllegalArgumentException<br />

IllegalStateException<br />

If nextSibling is not a sibling of node.<br />

If node is null and nextSibling is not null.<br />

Since 1.5<br />

Set the child node where the result nodes will be inserted be<strong>for</strong>e.<br />

In practice, nextSibling should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment node, or<br />

a org.w3c.dom.Element node. In other words, a node that accepts children.<br />

Use nextSibling to specify the child node where the result nodes should be inserted be<strong>for</strong>e. If nextSibling is<br />

not a sibling of node, then an IllegalArgumentException is thrown. If node is null and nextSibling<br />

is not null, then an IllegalStateException is thrown. If nextSibling is null. then the behavior is the<br />

same as calling javax.xml.trans<strong>for</strong>m.dom.DOMResult [ Constructor DOMResult(org.w3c.dom.Node)], i.e. append the<br />

result nodes as the last child of the specified node.<br />

Method setNode(Node)<br />

public void setNode(org.w3c.dom.Node node);<br />

Parameters<br />

node<br />

The node to which the trans<strong>for</strong>mation will be appended.<br />

Exceptions<br />

IllegalStateException<br />

IllegalStateException<br />

If nextSibling is not null and nextSibling is not a child of node.<br />

If node is null and nextSibling is not null.<br />

93


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

Set the node that will contain the result DOM tree.<br />

In practice, the node should be a org.w3c.dom.Document node, a org.w3c.dom.DocumentFragment node, or a<br />

org.w3c.dom.Element node. In other words, a node that accepts children.<br />

An IllegalStateException is thrown if nextSibling is not null and node is not a parent of nextSib<br />

ling. An IllegalStateException is thrown if node is null and nextSibling is not null.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URI string.<br />

Set the systemId that may be used in association with the node.<br />

Class DOMSource<br />

Synopsis<br />

Acts as a holder <strong>for</strong> a trans<strong>for</strong>mation Source tree in the <strong>for</strong>m of a Document Object Model (DOM) tree.<br />

}<br />

public DOMSourceimplements Source {<br />

public DOMSource();<br />

public DOMSource(org.w3c.dom.Node n);<br />

public DOMSource(org.w3c.dom.Node node,<br />

java.lang.String systemID);<br />

public void setNode(org.w3c.dom.Node node);<br />

public Node getNode();<br />

public void setSystemId(java.lang.String systemID);<br />

public String getSystemId();<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.5 $, $Date: 2003/12/06 00:21:46 $<br />

See Also<br />

Inheritance Path<br />

Document Object Model (DOM) Level 2 Specification [http://www.w3.org/TR/DOM-Level-2]<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.dom.DOMSource<br />

94


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

Members<br />

Constructor DOMSource()<br />

public DOMSource();<br />

See Also javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.trans<strong>for</strong>m [Method trans<strong>for</strong>m(javax.xml.trans<strong>for</strong>m.Source,<br />

javax.xml.trans<strong>for</strong>m.Result)]<br />

Zero-argument default constructor. If this constructor is used, and no DOM source is set using javax.xml.trans<br />

<strong>for</strong>m.dom.DOMSource.setNode [ Method setNode(org.w3c.dom.Node)] , then the Trans<strong>for</strong>mer will create an<br />

empty source org.w3c.dom.Document using javax.xml.parsers.DocumentBuilder#newDocument(). The Result of<br />

trans<strong>for</strong>ming an empty Source is always an empty Result.<br />

Constructor DOMSource(Node)<br />

public DOMSource(org.w3c.dom.Node n);<br />

Parameters<br />

nThe DOM node that will contain the Source tree.<br />

Create a new input source with a DOM node. The operation will be applied to the subtree rooted at this node. In XSLT,<br />

a "/" pattern still means the root of the tree (not the subtree), and the evaluation of global variables and parameters is<br />

done from the root node also.<br />

Constructor DOMSource(Node, String)<br />

public DOMSource(org.w3c.dom.Node node,<br />

java.lang.String systemID);<br />

Parameters<br />

node<br />

systemID<br />

The DOM node that will contain the Source tree.<br />

Specifies the base URI associated with node.<br />

Create a new input source with a DOM node, and with the system ID also passed in as the base URI.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>mer supports Source input of this type.<br />

Method getNode()<br />

public Node getNode();<br />

Get the node that represents a Source DOM tree.<br />

95


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.dom<br />

Community Draft<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the base ID (URL or system ID) from where URLs will be resolved.<br />

Method setNode(Node)<br />

public void setNode(org.w3c.dom.Node node);<br />

Parameters<br />

node<br />

The node that is to be trans<strong>for</strong>med.<br />

Set the node that will represents a Source DOM tree.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemID);<br />

Parameters<br />

systemID<br />

Base URL <strong>for</strong> this DOM tree.<br />

Set the base ID (URL or system ID) from where URLs will be resolved.<br />

Interface DOMLocator<br />

Synopsis<br />

Indicates the position of a node in a source DOM, intended primarily <strong>for</strong> error reporting. To use a DOMLocator, the<br />

receiver of an error must downcast the javax.xml.trans<strong>for</strong>m.SourceLocator [ Interface SourceLocator] object returned<br />

by an exception. A javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer] may use this object <strong>for</strong> purposes other than<br />

error reporting, <strong>for</strong> instance, to indicate the source node that originated a result node.<br />

implements public DOMLocator, SourceLocator {<br />

}<br />

public Node getOriginatingNode();<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.dom.DOMLocator<br />

Members<br />

Method getOriginatingNode()<br />

public Node getOriginatingNode();<br />

Return the node where the event occurred.<br />

96


Community Draft<br />

Community Draft<br />

Chapter 11. Package javax.xml.trans<strong>for</strong>m.sax<br />

This package implements SAX2-specific trans<strong>for</strong>mation <strong>API</strong>s. It provides classes which allow input from<br />

org.xml.sax.ContentHandler events, and also classes that produce org.xml.sax.ContentHandler events. It also provides<br />

methods to set the input source as an org.xml.sax.<strong>XML</strong>Reader, or to use a org.xml.sax.InputSource as the source. It<br />

also allows the creation of a org.xml.sax.<strong>XML</strong>Filter, which enables trans<strong>for</strong>mations to "pull" from other trans<strong>for</strong>mations,<br />

and lets the trans<strong>for</strong>mer to be used polymorphically as an org.xml.sax.<strong>XML</strong>Reader.<br />

The javax.xml.trans<strong>for</strong>m.sax.SAXSource [ Class SAXSource] class allows the setting of an org.xml.sax.<strong>XML</strong>Reader<br />

to be used <strong>for</strong> "pulling" parse events, and an org.xml.sax.InputSource that may be used to specify the SAX source.<br />

The javax.xml.trans<strong>for</strong>m.sax.SAXResult [ Class SAXResult] class allows the setting of a org.xml.sax.ContentHandler<br />

to be the receiver of SAX2 events from the trans<strong>for</strong>mation.<br />

The javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory [ Class SAXTrans<strong>for</strong>merFactory] extends javax.xml.trans<br />

<strong>for</strong>m.Trans<strong>for</strong>merFactory [ Class Trans<strong>for</strong>merFactory] to provide factory methods <strong>for</strong> creating javax.xml.trans<br />

<strong>for</strong>m.sax.TemplatesHandler [ Interface TemplatesHandler], javax.xml.trans<strong>for</strong>m.sax.Trans<strong>for</strong>merHandler [ Interface<br />

Trans<strong>for</strong>merHandler], and org.xml.sax.<strong>XML</strong>Reader instances.<br />

To obtain a javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory [ Class SAXTrans<strong>for</strong>merFactory], the caller must cast<br />

the javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory [ Class Trans<strong>for</strong>merFactory] instance returned from javax.xml.trans<br />

<strong>for</strong>m.Trans<strong>for</strong>merFactory.newInstance [ Method newInstance()].<br />

The javax.xml.trans<strong>for</strong>m.sax.Trans<strong>for</strong>merHandler [ Interface Trans<strong>for</strong>merHandler] interface allows a trans<strong>for</strong>mation<br />

to be created from SAX2 parse events, which is a "push" model rather than the "pull" model that normally occurs <strong>for</strong><br />

a trans<strong>for</strong>mation. Normal parse events are received through the org.xml.sax.ContentHandler interface, lexical events<br />

such as startCDATA and endCDATA are received through the org.xml.sax.ext.LexicalHandler interface, and events<br />

that signal the start or end of disabling output escaping are received via org.xml.sax.ContentHandler.processingInstruc<br />

tion, with the target parameter being javax.xml.trans<strong>for</strong>m.Result.PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG [ Field<br />

PI_DISABLE_OUTPUT_ESC<strong>API</strong>NG] and javax.xml.trans<strong>for</strong>m.Result.PI_ENABLE_OUTPUT_ESC<strong>API</strong>NG [ Field<br />

PI_ENABLE_OUTPUT_ESC<strong>API</strong>NG]. If parameters, output properties, or other features need to be set on the Trans<br />

<strong>for</strong>mer handler, a javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer] reference will need to be obtained from<br />

javax.xml.trans<strong>for</strong>m.sax.Trans<strong>for</strong>merHandler.getTrans<strong>for</strong>mer [ Method getTrans<strong>for</strong>mer()], and the methods invoked<br />

from that reference.<br />

The javax.xml.trans<strong>for</strong>m.sax.TemplatesHandler [ Interface TemplatesHandler] interface allows the creation of<br />

javax.xml.trans<strong>for</strong>m.Templates [ Interface Templates] objects from SAX2 parse events. Once the org.xml.sax.Con<br />

tentHandler events are complete, the Templates object may be obtained from javax.xml.trans<strong>for</strong>m.sax.TemplatesHand<br />

ler.getTemplates [ Method getTemplates()]. Note that javax.xml.trans<strong>for</strong>m.sax.TemplatesHandler.setSystemId [<br />

Method setSystemId(java.lang.String)] should normally be called in order to establish a base system ID from which<br />

relative URLs may be resolved.<br />

The javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory.new<strong>XML</strong>Filter [ Method new<strong>XML</strong>Filter(javax.xml.trans<br />

<strong>for</strong>m.Source)] method allows the creation of a org.xml.sax.<strong>XML</strong>Filter, which encapsulates the SAX2 notion of a "pull"<br />

trans<strong>for</strong>mation. The following illustrates several trans<strong>for</strong>mations chained together. Each filter points to a parent<br />

org.xml.sax.<strong>XML</strong>Reader, and the final trans<strong>for</strong>mation is caused by invoking org.xml.sax.<strong>XML</strong>Reader.parse on the final<br />

reader in the chain.<br />

Class SAXResult<br />

Acts as an holder <strong>for</strong> a trans<strong>for</strong>mation Result.<br />

97


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Synopsis<br />

public SAXResultimplements Result {<br />

public SAXResult();<br />

public SAXResult(org.xml.sax.ContentHandler handler);<br />

public void setHandler(org.xml.sax.ContentHandler handler);<br />

public ContentHandler getHandler();<br />

public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler);<br />

public LexicalHandler getLexicalHandler();<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.sax.SAXResult<br />

Members<br />

Constructor SAXResult()<br />

public SAXResult();<br />

Zero-argument default constructor.<br />

Constructor SAXResult(ContentHandler)<br />

public SAXResult(org.xml.sax.ContentHandler handler);<br />

Parameters<br />

handler<br />

Must be a non-null ContentHandler reference.<br />

Create a SAXResult that targets a SAX2 org.xml.sax.ContentHandler.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>mer supports Result output of this type.<br />

98


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Method getHandler()<br />

public ContentHandler getHandler();<br />

Get the org.xml.sax.ContentHandler that is the Result.<br />

Method getLexicalHandler()<br />

public LexicalHandler getLexicalHandler();<br />

Get a SAX2 org.xml.sax.ext.LexicalHandler <strong>for</strong> the output.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the system identifier that was set with setSystemId.<br />

Method setHandler(ContentHandler)<br />

public void setHandler(org.xml.sax.ContentHandler handler);<br />

Parameters<br />

handler<br />

Must be a non-null ContentHandler reference.<br />

Set the target to be a SAX2 org.xml.sax.ContentHandler.<br />

Method setLexicalHandler(LexicalHandler)<br />

public void setLexicalHandler(org.xml.sax.ext.LexicalHandler handler);<br />

Parameters<br />

handler<br />

A non-null LexicalHandler <strong>for</strong> handling lexical parse events.<br />

Set the SAX2 org.xml.sax.ext.LexicalHandler <strong>for</strong> the output.<br />

This is needed to handle <strong>XML</strong> comments and the like. If the lexical handler is not set, an attempt should be made by<br />

the trans<strong>for</strong>mer to cast the org.xml.sax.ContentHandler to a LexicalHandler.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URI string.<br />

Method setSystemId Set the systemID that may be used in association with the org.xml.sax.ContentHandler.<br />

99


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Class SAXSource<br />

Synopsis<br />

Acts as an holder <strong>for</strong> SAX-style Source.<br />

}<br />

public SAXSourceimplements Source {<br />

public SAXSource();<br />

public SAXSource(org.xml.sax.<strong>XML</strong>Reader reader,<br />

org.xml.sax.InputSource inputSource);<br />

public SAXSource(org.xml.sax.InputSource inputSource);<br />

public void set<strong>XML</strong>Reader(org.xml.sax.<strong>XML</strong>Reader reader);<br />

public <strong>XML</strong>Reader get<strong>XML</strong>Reader();<br />

public void setInputSource(org.xml.sax.InputSource inputSource);<br />

public InputSource getInputSource();<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

static InputSource sourceToInputSource(javax.xml.trans<strong>for</strong>m.Source source);<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.7 $, $Date: 2003/12/06 00:21:44 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.sax.SAXSource<br />

Members<br />

Constructor SAXSource()<br />

public SAXSource();<br />

See Also javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.trans<strong>for</strong>m [Method trans<strong>for</strong>m(javax.xml.trans<strong>for</strong>m.Source,<br />

javax.xml.trans<strong>for</strong>m.Result)]<br />

Zero-argument default constructor. If this constructor is used, and no SAX source is set using javax.xml.trans<br />

<strong>for</strong>m.sax.SAXSource.setInputSource [ Method setInputSource(org.xml.sax.InputSource)] , then the Trans<strong>for</strong>mer<br />

will create an empty source org.xml.sax.InputSource using new InputSource(). The Result of trans<strong>for</strong>ming an empty<br />

Source is always an empty Result.<br />

100


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Constructor SAXSource(InputSource)<br />

public SAXSource(org.xml.sax.InputSource inputSource);<br />

Parameters<br />

inputSource<br />

An input source reference that must be non-null and that will be passed to the parse method<br />

of the reader.<br />

Create a SAXSource, using a SAX InputSource. The javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer [ Class Trans<strong>for</strong>mer] or<br />

javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory [ Class SAXTrans<strong>for</strong>merFactory] creates a reader via<br />

org.xml.sax.helpers.<strong>XML</strong>ReaderFactory (if set<strong>XML</strong>Reader is not used), sets itself as the reader's org.xml.sax.Con<br />

tentHandler, and calls reader.parse(inputSource).<br />

Constructor SAXSource(<strong>XML</strong>Reader, InputSource)<br />

public SAXSource(org.xml.sax.<strong>XML</strong>Reader reader,<br />

org.xml.sax.InputSource inputSource);<br />

Parameters<br />

reader<br />

inputSource<br />

An <strong>XML</strong>Reader to be used <strong>for</strong> the parse.<br />

A SAX input source reference that must be non-null and that will be passed to the reader<br />

parse method.<br />

Create a SAXSource, using an org.xml.sax.<strong>XML</strong>Reader and a SAX InputSource. The javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer<br />

[ Class Trans<strong>for</strong>mer] or javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory [ Class SAXTrans<strong>for</strong>merFactory] will set<br />

itself to be the reader's org.xml.sax.ContentHandler, and then will call reader.parse(inputSource).<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>mer supports Source input of this type.<br />

Method getInputSource()<br />

public InputSource getInputSource();<br />

Get the SAX InputSource to be used <strong>for</strong> the Source.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the base ID (URI or system ID) from where URIs will be resolved.<br />

Method get<strong>XML</strong>Reader()<br />

public <strong>XML</strong>Reader get<strong>XML</strong>Reader();<br />

Get the <strong>XML</strong>Reader to be used <strong>for</strong> the Source.<br />

101


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Method setInputSource(InputSource)<br />

public void setInputSource(org.xml.sax.InputSource inputSource);<br />

Parameters<br />

inputSource<br />

A valid InputSource reference.<br />

Set the SAX InputSource to be used <strong>for</strong> the Source.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URI string.<br />

Set the system identifier <strong>for</strong> this Source. If an input source has already been set, it will set the system ID or that input<br />

source, otherwise it will create a new input source.<br />

The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since<br />

the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will<br />

attempt to open a connection to the URI only if no byte stream or character stream is specified).<br />

Method set<strong>XML</strong>Reader(<strong>XML</strong>Reader)<br />

public void set<strong>XML</strong>Reader(org.xml.sax.<strong>XML</strong>Reader reader);<br />

Parameters<br />

reader<br />

A valid <strong>XML</strong>Reader or <strong>XML</strong>Filter reference.<br />

Set the <strong>XML</strong>Reader to be used <strong>for</strong> the Source.<br />

Method sourceToInputSource(Source)<br />

static InputSource sourceToInputSource(javax.xml.trans<strong>for</strong>m.Source source);<br />

Parameters<br />

source<br />

returns<br />

Must be a non-null Source reference.<br />

An InputSource, or null if Source can not be converted.<br />

Attempt to obtain a SAX InputSource object from a Source object.<br />

Class SAXTrans<strong>for</strong>merFactory<br />

This class extends Trans<strong>for</strong>merFactory to provide SAX-specific factory methods. It provides two types of ContentHand<br />

lers, one <strong>for</strong> creating Trans<strong>for</strong>mers, the other <strong>for</strong> creating Templates objects.<br />

102


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Synopsis<br />

If an application wants to set the ErrorHandler or EntityResolver <strong>for</strong> an <strong>XML</strong>Reader used during a trans<strong>for</strong>mation, it<br />

should use a URIResolver to return the SAXSource which provides (with get<strong>XML</strong>Reader) a reference to the <strong>XML</strong>Reader.<br />

}<br />

public SAXTrans<strong>for</strong>merFactory extends Trans<strong>for</strong>merFactory {<br />

protected SAXTrans<strong>for</strong>merFactory();<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler(javax.xml.trans<strong>for</strong>m.Source src)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler(javax.xml.trans<strong>for</strong>m.Templates te<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler()<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

public TemplatesHandler abstract newTemplatesHandler()<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

public <strong>XML</strong>Filter abstract new<strong>XML</strong>Filter(javax.xml.trans<strong>for</strong>m.Source src)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

public <strong>XML</strong>Filter abstract new<strong>XML</strong>Filter(javax.xml.trans<strong>for</strong>m.Templates templates)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory<br />

|<br />

javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory<br />

Members<br />

Constructor SAXTrans<strong>for</strong>merFactory()<br />

protected SAXTrans<strong>for</strong>merFactory();<br />

The default constructor is protected on purpose.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>merFactory returned from javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.newInstance<br />

[ Method newInstance()] may be safely cast to a SAXTrans<strong>for</strong>merFactory.<br />

103


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Field FEATURE_<strong>XML</strong>FILTER<br />

static java.lang.String FEATURE_<strong>XML</strong>FILTER ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory.new<strong>XML</strong>Filter [ Method new<strong>XML</strong><br />

Filter(javax.xml.trans<strong>for</strong>m.Source)] and javax.xml.trans<strong>for</strong>m.sax.SAXTrans<strong>for</strong>merFactory.new<strong>XML</strong>Filter [ Method<br />

new<strong>XML</strong>Filter(javax.xml.trans<strong>for</strong>m.Templates)] methods are supported.<br />

Method newTemplatesHandler()<br />

public TemplatesHandler abstract newTemplatesHandler()<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the TemplatesHandler cannot be created.<br />

Get a TemplatesHandler object that can process SAX ContentHandler events into a Templates object.<br />

Method newTrans<strong>for</strong>merHandler()<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler()<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the Trans<strong>for</strong>merHandler cannot be created.<br />

Get a Trans<strong>for</strong>merHandler object that can process SAX ContentHandler events into a Result. The trans<strong>for</strong>mation is<br />

defined as an identity (or copy) trans<strong>for</strong>mation, <strong>for</strong> example to copy a series of SAX parse events into a DOM tree.<br />

Method newTrans<strong>for</strong>merHandler(Source)<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler(javax.xml.trans<strong>for</strong>m.Source src)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

src<br />

returns<br />

The Source of the trans<strong>for</strong>mation instructions.<br />

Trans<strong>for</strong>merHandler ready to trans<strong>for</strong>m SAX events.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the Trans<strong>for</strong>merHandler can not be created.<br />

Get a Trans<strong>for</strong>merHandler object that can process SAX ContentHandler events into a Result, based on the trans<strong>for</strong>mation<br />

instructions specified by the argument.<br />

104


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Method newTrans<strong>for</strong>merHandler(Templates)<br />

public Trans<strong>for</strong>merHandler abstract newTrans<strong>for</strong>merHandler(javax.xml.trans<strong>for</strong>m.Templates te<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

templates<br />

returns<br />

The compiled trans<strong>for</strong>mation instructions.<br />

Trans<strong>for</strong>merHandler ready to trans<strong>for</strong>m SAX events.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the Trans<strong>for</strong>merHandler can not be created.<br />

Get a Trans<strong>for</strong>merHandler object that can process SAX ContentHandler events into a Result, based on the Templates<br />

argument.<br />

Method new<strong>XML</strong>Filter(Source)<br />

public <strong>XML</strong>Filter abstract new<strong>XML</strong>Filter(javax.xml.trans<strong>for</strong>m.Source src)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

src<br />

returns<br />

The Source of the trans<strong>for</strong>mation instructions.<br />

An <strong>XML</strong>Filter object, or null if this feature is not supported.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the TemplatesHandler cannot be created.<br />

Create an <strong>XML</strong>Filter that uses the given Source as the trans<strong>for</strong>mation instructions.<br />

Method new<strong>XML</strong>Filter(Templates)<br />

public <strong>XML</strong>Filter abstract new<strong>XML</strong>Filter(javax.xml.trans<strong>for</strong>m.Templates templates)<br />

throws javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merConfigurationException;<br />

Parameters<br />

templates<br />

returns<br />

The compiled trans<strong>for</strong>mation instructions.<br />

An <strong>XML</strong>Filter object, or null if this feature is not supported.<br />

Exceptions<br />

Trans<strong>for</strong>merConfigura<br />

tionException<br />

If <strong>for</strong> some reason the TemplatesHandler cannot be created.<br />

Create an <strong>XML</strong>Filter, based on the Templates argument..<br />

105


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Interface TemplatesHandler<br />

Synopsis<br />

A SAX ContentHandler that may be used to process SAX parse events (parsing trans<strong>for</strong>mation instructions) into a<br />

Templates object.<br />

Note that TemplatesHandler does not need to implement LexicalHandler.<br />

implements public TemplatesHandler, ContentHandler {<br />

}<br />

public Templates getTemplates();<br />

public void setSystemId(java.lang.String systemID);<br />

public String getSystemId();<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.sax.TemplatesHandler<br />

Members<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the base ID (URI or system ID) from where relative URLs will be resolved.<br />

Method getTemplates()<br />

public Templates getTemplates();<br />

When a TemplatesHandler object is used as a ContentHandler <strong>for</strong> the parsing of trans<strong>for</strong>mation instructions, it creates<br />

a Templates object, which the caller can get once the SAX events have been completed.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemID);<br />

Parameters<br />

systemID<br />

Base URI <strong>for</strong> this stylesheet.<br />

Set the base ID (URI or system ID) <strong>for</strong> the Templates object created by this builder. This must be set in order to resolve<br />

relative URIs in the stylesheet. This must be called be<strong>for</strong>e the startDocument event.<br />

Interface Trans<strong>for</strong>merHandler<br />

A Trans<strong>for</strong>merHandler listens <strong>for</strong> SAX ContentHandler parse events and trans<strong>for</strong>ms them to a Result.<br />

106


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Synopsis<br />

implements public Trans<strong>for</strong>merHandler, ContentHandler, LexicalHandler, DTDHandler {<br />

}<br />

public void setResult(javax.xml.trans<strong>for</strong>m.Result result)<br />

throws java.lang.IllegalArgumentException;<br />

public void setSystemId(java.lang.String systemID);<br />

public String getSystemId();<br />

public Trans<strong>for</strong>mer getTrans<strong>for</strong>mer();<br />

Inheritance Path<br />

javax.xml.trans<strong>for</strong>m.sax.Trans<strong>for</strong>merHandler<br />

Members<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the base ID (URI or system ID) from where relative URLs will be resolved.<br />

Method getTrans<strong>for</strong>mer()<br />

public Trans<strong>for</strong>mer getTrans<strong>for</strong>mer();<br />

Get the Trans<strong>for</strong>mer associated with this handler, which is needed in order to set parameters and output properties.<br />

Method setResult(Result)<br />

public void setResult(javax.xml.trans<strong>for</strong>m.Result result)<br />

throws java.lang.IllegalArgumentException;<br />

Parameters<br />

result<br />

A Result instance, should not be null.<br />

Exceptions<br />

IllegalArgumentException<br />

if result is invalid <strong>for</strong> some reason.<br />

Set the Result associated with this Trans<strong>for</strong>merHandler to be used <strong>for</strong> the trans<strong>for</strong>mation.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemID);<br />

107


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.sax<br />

Community Draft<br />

Parameters<br />

systemID<br />

Base URI <strong>for</strong> the source tree.<br />

Set the base ID (URI or system ID) from where relative URLs will be resolved.<br />

108


Community Draft<br />

Community Draft<br />

C h a p t e r 1 2 . P a c k a g e<br />

javax.xml.trans<strong>for</strong>m.stream<br />

This package implements stream- and URI- specific trans<strong>for</strong>mation <strong>API</strong>s.<br />

The javax.xml.trans<strong>for</strong>m.stream.StreamSource [ Class StreamSource] class provides methods <strong>for</strong> specifying<br />

java.io.InputStream input, java.io.Reader input, and URL input in the <strong>for</strong>m of strings. Even if an input stream or<br />

reader is specified as the source, javax.xml.trans<strong>for</strong>m.stream.StreamSource.setSystemId [ Method setSys<br />

temId(java.lang.String)] should still be called, so that the trans<strong>for</strong>mer can know from where it should resolve relative<br />

URIs. The public identifier is always optional: if the application writer includes one, it will be provided as part of the<br />

javax.xml.trans<strong>for</strong>m.SourceLocator [ Interface SourceLocator] in<strong>for</strong>mation.<br />

The javax.xml.trans<strong>for</strong>m.stream.StreamResult [ Class StreamResult] class provides methods <strong>for</strong> specifying<br />

java.io.OutputStream, java.io.Writer, or an output system ID, as the output of the trans<strong>for</strong>mation result.<br />

Normally streams should be used rather than readers or writers, <strong>for</strong> both the Source and Result, since readers and<br />

writers already have the encoding established to and from the internal Unicode <strong>for</strong>mat. However, there are times when<br />

it is useful to write to a character stream, such as when using a StringWriter in order to write to a String, or in the case<br />

of reading source <strong>XML</strong> from a StringReader.<br />

Class StreamResult<br />

Synopsis<br />

Acts as an holder <strong>for</strong> a trans<strong>for</strong>mation result, which may be <strong>XML</strong>, plain Text, HTML, or some other <strong>for</strong>m of markup.<br />

public StreamResultimplements Result {<br />

public StreamResult();<br />

public StreamResult(java.io.OutputStream outputStream);<br />

public StreamResult(java.io.Writer writer);<br />

public StreamResult(java.lang.String systemId);<br />

public StreamResult(java.io.File f);<br />

public void setOutputStream(java.io.OutputStream outputStream);<br />

public OutputStream getOutputStream();<br />

public void setWriter(java.io.Writer writer);<br />

public Writer getWriter();<br />

public void setSystemId(java.lang.String systemId);<br />

public void setSystemId(java.io.File f);<br />

public String getSystemId();<br />

109


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.stream.StreamResult<br />

Members<br />

Constructor StreamResult()<br />

public StreamResult();<br />

Zero-argument default constructor.<br />

Constructor StreamResult(File)<br />

public StreamResult(java.io.File f);<br />

Parameters<br />

fMust a non-null File reference.<br />

Construct a StreamResult from a File.<br />

Constructor StreamResult(OutputStream)<br />

public StreamResult(java.io.OutputStream outputStream);<br />

Parameters<br />

outputStream<br />

A valid OutputStream reference.<br />

Construct a StreamResult from a byte stream. Normally, a stream should be used rather than a reader, so that the<br />

trans<strong>for</strong>mer may use instructions contained in the trans<strong>for</strong>mation instructions to control the encoding.<br />

Constructor StreamResult(String)<br />

public StreamResult(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

Must be a String that con<strong>for</strong>ms to the URI syntax.<br />

Construct a StreamResult from a URL.<br />

Constructor StreamResult(Writer)<br />

public StreamResult(java.io.Writer writer);<br />

110


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

Parameters<br />

writer<br />

A valid Writer reference.<br />

Construct a StreamResult from a character stream. Normally, a stream should be used rather than a reader, so that the<br />

trans<strong>for</strong>mer may use instructions contained in the trans<strong>for</strong>mation instructions to control the encoding. However, there<br />

are times when it is useful to write to a character stream, such as when using a StringWriter.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>mer supports Result output of this type.<br />

Method getOutputStream()<br />

public OutputStream getOutputStream();<br />

Get the byte stream that was set with setOutputStream.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the system identifier that was set with setSystemId.<br />

Method getWriter()<br />

public Writer getWriter();<br />

Get the character stream that was set with setWriter.<br />

Method setOutputStream(OutputStream)<br />

public void setOutputStream(java.io.OutputStream outputStream);<br />

Parameters<br />

outputStream<br />

A valid OutputStream reference.<br />

Set the ByteStream that is to be written to. Normally, a stream should be used rather than a reader, so that the trans<strong>for</strong>mer<br />

may use instructions contained in the trans<strong>for</strong>mation instructions to control the encoding.<br />

Method setSystemId(File)<br />

public void setSystemId(java.io.File f);<br />

Parameters<br />

fMust a non-null File reference.<br />

Set the system ID from a File reference.<br />

111


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URI string.<br />

Set the systemID that may be used in association with the byte or character stream, or, if neither is set, use this value<br />

as a writeable URI (probably a file name).<br />

Method setWriter(Writer)<br />

public void setWriter(java.io.Writer writer);<br />

Parameters<br />

writer<br />

A valid Writer reference.<br />

Set the writer that is to receive the result. Normally, a stream should be used rather than a writer, so that the trans<strong>for</strong>mer<br />

may use instructions contained in the trans<strong>for</strong>mation instructions to control the encoding. However, there are times<br />

when it is useful to write to a writer, such as when using a StringWriter.<br />

Class StreamSource<br />

Synopsis<br />

Acts as an holder <strong>for</strong> a trans<strong>for</strong>mation Source in the <strong>for</strong>m of a stream of <strong>XML</strong> markup.<br />

public StreamSourceimplements Source {<br />

public StreamSource();<br />

public StreamSource(java.io.InputStream inputStream);<br />

public StreamSource(java.io.InputStream inputStream,<br />

java.lang.String systemId);<br />

public StreamSource(java.io.Reader reader);<br />

public StreamSource(java.io.Reader reader,<br />

java.lang.String systemId);<br />

public StreamSource(java.lang.String systemId);<br />

public StreamSource(java.io.File f);<br />

public void setInputStream(java.io.InputStream inputStream);<br />

public InputStream getInputStream();<br />

public void setReader(java.io.Reader reader);<br />

public Reader getReader();<br />

112


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

public void setPublicId(java.lang.String publicId);<br />

public String getPublicId();<br />

public void setSystemId(java.lang.String systemId);<br />

public String getSystemId();<br />

public void setSystemId(java.io.File f);<br />

}<br />

Author<br />

Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.5 $, $Date: 2003/12/06 00:21:33 $<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.trans<strong>for</strong>m.stream.StreamSource<br />

Members<br />

Constructor StreamSource()<br />

public StreamSource();<br />

See Also javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.trans<strong>for</strong>m [Method trans<strong>for</strong>m(javax.xml.trans<strong>for</strong>m.Source,<br />

javax.xml.trans<strong>for</strong>m.Result)]<br />

Zero-argument default constructor. If this constructor is used, and no Stream source is set using javax.xml.trans<br />

<strong>for</strong>m.stream.StreamSource.setInputStream [ Method setInputStream(java.io.InputStream)] or javax.xml.trans<br />

<strong>for</strong>m.stream.StreamSource.setReader [ Method setReader(java.io.Reader)], then the Trans<strong>for</strong>mer will create an<br />

empty source java.io.InputStream using new InputStream(). The Result of trans<strong>for</strong>ming an empty Source is always<br />

an empty Result.<br />

Constructor StreamSource(File)<br />

public StreamSource(java.io.File f);<br />

Parameters<br />

fMust a non-null File reference.<br />

Construct a StreamSource from a File.<br />

Constructor StreamSource(InputStream)<br />

public StreamSource(java.io.InputStream inputStream);<br />

Parameters<br />

inputStream<br />

A valid InputStream reference to an <strong>XML</strong> stream.<br />

113


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so the <strong>XML</strong><br />

parser can resolve character encoding specified by the <strong>XML</strong> declaration.<br />

If this constructor is used to process a stylesheet, normally setSystemId should also be called, so that relative URI<br />

references can be resolved.<br />

Constructor StreamSource(InputStream, String)<br />

public StreamSource(java.io.InputStream inputStream,<br />

java.lang.String systemId);<br />

Parameters<br />

inputStream<br />

systemId<br />

A valid InputStream reference to an <strong>XML</strong> stream.<br />

Must be a String that con<strong>for</strong>ms to the URI syntax.<br />

Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so that the <strong>XML</strong><br />

parser can resolve character encoding specified by the <strong>XML</strong> declaration.<br />

This constructor allows the systemID to be set in addition to the input stream, which allows relative URIs to be processed.<br />

Constructor StreamSource(Reader)<br />

public StreamSource(java.io.Reader reader);<br />

Parameters<br />

reader<br />

A valid Reader reference to an <strong>XML</strong> character stream.<br />

Construct a StreamSource from a character reader. Normally, a stream should be used rather than a reader, so that the<br />

<strong>XML</strong> parser can resolve character encoding specified by the <strong>XML</strong> declaration. However, in many cases the encoding<br />

of the input stream is already resolved, as in the case of reading <strong>XML</strong> from a StringReader.<br />

Constructor StreamSource(Reader, String)<br />

public StreamSource(java.io.Reader reader,<br />

java.lang.String systemId);<br />

Parameters<br />

reader<br />

systemId<br />

A valid Reader reference to an <strong>XML</strong> character stream.<br />

Must be a String that con<strong>for</strong>ms to the URI syntax.<br />

Construct a StreamSource from a character reader. Normally, a stream should be used rather than a reader, so that the<br />

<strong>XML</strong> parser may resolve character encoding specified by the <strong>XML</strong> declaration. However, in many cases the encoding<br />

of the input stream is already resolved, as in the case of reading <strong>XML</strong> from a StringReader.<br />

Constructor StreamSource(String)<br />

public StreamSource(java.lang.String systemId);<br />

114


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

Parameters<br />

systemId<br />

Must be a String that con<strong>for</strong>ms to the URI syntax.<br />

Construct a StreamSource from a URL.<br />

Field FEATURE<br />

static java.lang.String FEATURE ;<br />

If javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.getFeature [ Method getFeature(java.lang.String)] returns true when passed<br />

this value as an argument, the Trans<strong>for</strong>mer supports Source input of this type.<br />

Method getInputStream()<br />

public InputStream getInputStream();<br />

Get the byte stream that was set with setByteStream.<br />

Method getPublicId()<br />

public String getPublicId();<br />

Get the public identifier that was set with setPublicId.<br />

Method getReader()<br />

public Reader getReader();<br />

Get the character stream that was set with setReader.<br />

Method getSystemId()<br />

public String getSystemId();<br />

Get the system identifier that was set with setSystemId.<br />

Method setInputStream(InputStream)<br />

public void setInputStream(java.io.InputStream inputStream);<br />

Parameters<br />

inputStream<br />

A valid InputStream reference to an <strong>XML</strong> stream.<br />

Set the byte stream to be used as input. Normally, a stream should be used rather than a reader, so that the <strong>XML</strong> parser<br />

can resolve character encoding specified by the <strong>XML</strong> declaration.<br />

If this Source object is used to process a stylesheet, normally setSystemId should also be called, so that relative URL<br />

references can be resolved.<br />

Method setPublicId(String)<br />

public void setPublicId(java.lang.String publicId);<br />

115


Community Draft<br />

Package javax.xml.trans<strong>for</strong>m.stream<br />

Community Draft<br />

Parameters<br />

publicId<br />

The public identifier as a string.<br />

Set the public identifier <strong>for</strong> this Source.<br />

The public identifier is always optional: if the application writer includes one, it will be provided as part of the location<br />

in<strong>for</strong>mation.<br />

Method setReader(Reader)<br />

public void setReader(java.io.Reader reader);<br />

Parameters<br />

reader<br />

A valid Reader reference to an <strong>XML</strong> CharacterStream.<br />

Set the input to be a character reader. Normally, a stream should be used rather than a reader, so that the <strong>XML</strong> parser<br />

can resolve character encoding specified by the <strong>XML</strong> declaration. However, in many cases the encoding of the input<br />

stream is already resolved, as in the case of reading <strong>XML</strong> from a StringReader.<br />

Method setSystemId(File)<br />

public void setSystemId(java.io.File f);<br />

Parameters<br />

fMust a non-null File reference.<br />

Set the system ID from a File reference.<br />

Method setSystemId(String)<br />

public void setSystemId(java.lang.String systemId);<br />

Parameters<br />

systemId<br />

The system identifier as a URL string.<br />

Set the system identifier <strong>for</strong> this Source.<br />

The system identifier is optional if there is a byte stream or a character stream, but it is still useful to provide one, since<br />

the application can use it to resolve relative URIs and can include it in error messages and warnings (the parser will<br />

attempt to open a connection to the URI only if there is no byte stream or character stream specified).<br />

116


Community Draft<br />

Community Draft<br />

Chapter 13. Package javax.xml.namespace<br />

<strong>XML</strong> Namespace processing.<br />

The following <strong>XML</strong> standards apply:<br />

• <strong>XML</strong> Schema Part2: Datatypes specification [http://www.w3.org/TR/xmlschema-2/#QName]<br />

• Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

• Namespaces in <strong>XML</strong> Errata [http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

Class QName<br />

Synopsis<br />

QName represents a qualified name as defined in the <strong>XML</strong> specifications: <strong>XML</strong> Schema Part2: Datatypes specification<br />

[http://www.w3.org/TR/xmlschema-2/#QName], Namespaces in <strong>XML</strong><br />

[http://www.w3.org/TR/REC-xml-names/#ns-qualnames], Namespaces in <strong>XML</strong> Errata<br />

[http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata].<br />

The value of a QName contains a Namespace URI, local part and prefix.<br />

The prefix is included in QName to retain lexical in<strong>for</strong>mation when present in an <strong>XML</strong> input source. The prefix is NOT<br />

used in QName.equals(Object) [ Method equals(java.lang.Object)] or to compute the QName.hashCode() [ Method<br />

hashCode()]. Equality and the hash code are defined using only the Namespace URI and local part.<br />

If not specified, the Namespace URI is set to <strong>XML</strong>Constants.NULL_NS_URI. If not specified, the prefix is set to XM<br />

LConstants.DEFAULT_NS_PREFIX.<br />

QName is immutable.<br />

public QNameimplements Serializable {<br />

public QName(java.lang.String namespaceURI,<br />

java.lang.String localPart);<br />

public QName(java.lang.String namespaceURI,<br />

java.lang.String localPart,<br />

java.lang.String prefix);<br />

public QName(java.lang.String localPart);<br />

public String getNamespaceURI();<br />

public String getLocalPart();<br />

public String getPrefix();<br />

final boolean equals(java.lang.Object objectToTest);<br />

final int hashCode();<br />

public String toString();<br />

117


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

static QName valueOf(java.lang.String qNameAsString);<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.8 $, $Date: 2003/12/12 00:40:22 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

<strong>XML</strong> Schema Part2: Datatypes specification [http://www.w3.org/TR/xmlschema-2/#QName],<br />

Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/#ns-qualnames], Namespaces in<br />

<strong>XML</strong> Errata [http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

java.lang.Object<br />

|<br />

javax.xml.namespace.QName<br />

Members<br />

Constructor QName(String)<br />

public QName(java.lang.String localPart);<br />

Parameters<br />

localPart<br />

local part of the QName<br />

See Also QName(String namespaceURI, String localPart) [Constructor QName(java.lang.String,<br />

java.lang.String)], QName(String namespaceURI, String localPart, String prefix) [Constructor<br />

QName(java.lang.String, java.lang.String, java.lang.String)]<br />

QName constructor specifying the local part.<br />

If the local part is null an IllegalArgumentException is thrown. A local part of "" is allowed to preserve<br />

compatible behavior with QName 1.0.<br />

When using this constructor, the Namespace URI is set to <strong>XML</strong>Constants.NULL_NS_URI and the prefix is set to XM<br />

LConstants.DEFAULT_NS_PREFIX.<br />

In an <strong>XML</strong> context, all Element and Attribute names exist in the context of a Namespace. Making this explicit during<br />

the construction of a QName helps prevent hard to diagnosis <strong>XML</strong> validity errors. The constructors QName(String<br />

namespaceURI, String localPart) [Constructor QName(java.lang.String, java.lang.String)] and<br />

javax.xml.namespace.QName [Constructor QName(java.lang.String, java.lang.String, java.lang.String)] are preferred.<br />

The local part is not validated as a NCName [http://www.w3.org/TR/REC-xml-names/#NT-NCName] as specified in<br />

Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/]. <strong>XML</strong>Utils.isValidNCName(NCName) and <strong>XML</strong>Utils.is<br />

ValidNCName(ncName, xmlVersion) can be used to validate NCNames.<br />

118


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

Constructor QName(String, String)<br />

public QName(java.lang.String namespaceURI,<br />

java.lang.String localPart);<br />

Parameters<br />

namespaceURI<br />

localPart<br />

See Also<br />

Namespace URI of the QName<br />

local part of the QName<br />

QName(String namespaceURI, String localPart, String prefix) [Constructor QName(java.lang.String,<br />

java.lang.String, java.lang.String)]<br />

QName constructor specifying the Namespace URI and local part.<br />

If the Namespace URI is null, it is set to <strong>XML</strong>Constants.NULL_NS_URI. This value represents no explicitly defined<br />

Namespace as defined by the Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/#ns-qualnames] specific<br />

ation. This action preserves compatible behavior with QName 1.0. Explicitly providing the <strong>XML</strong>Con<br />

stants.NULL_NS_URI value is the preferred coding style.<br />

If the local part is null an IllegalArgumentException is thrown. A local part of "" is allowed to preserve<br />

compatible behavior with QName 1.0.<br />

When using this constructor, the prefix is set to <strong>XML</strong>Constants.DEFAULT_NS_PREFIX.<br />

The Namespace URI is not validated as a URI reference [http://www.ietf.org/rfc/rfc2396.txt]. The local part is not<br />

validated as a NCName [http://www.w3.org/TR/REC-xml-names/#NT-NCName] as specified in Namespaces in <strong>XML</strong><br />

[http://www.w3.org/TR/REC-xml-names/]. <strong>XML</strong>Utils.isValidNCName(NCName) and <strong>XML</strong>Utils.isValidNCName(nc<br />

Name, xmlVersion) can be used to validate NCNames.<br />

Constructor QName(String, String, String)<br />

public QName(java.lang.String namespaceURI,<br />

java.lang.String localPart,<br />

java.lang.String prefix);<br />

Parameters<br />

namespaceURI<br />

localPart<br />

prefix<br />

Namespace URI of the QName<br />

local part of the QName<br />

prefix of the QName<br />

QName constructor specifying the Namespace URI, local part and prefix.<br />

If the Namespace URI is null, it is set to <strong>XML</strong>Constants.NULL_NS_URI. This value represents no explicitly defined<br />

Namespace as defined by the Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/#ns-qualnames] specific<br />

ation. This action preserves compatible behavior with QName 1.0. Explicitly providing the <strong>XML</strong>Con<br />

stants.NULL_NS_URI value is the preferred coding style.<br />

If the local part is null an IllegalArgumentException is thrown. A local part of "" is allowed to preserve<br />

compatible behavior with QName 1.0.<br />

119


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

If the prefix is null, an IllegalArgumentException is thrown. Use <strong>XML</strong>Constants.DEFAULT_NS_PREFIX<br />

to explicitly indicate that no prefix is present or the prefix is not relevant.<br />

The Namespace URI is not validated as a URI reference [http://www.ietf.org/rfc/rfc2396.txt]. The local part and prefix<br />

are not validated as a NCName [http://www.w3.org/TR/REC-xml-names/#NT-NCName] as specified in Namespaces<br />

in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/]. <strong>XML</strong>Utils.isValidNCName(NCName) and <strong>XML</strong>Utils.isValidNC<br />

Name(ncName, xmlVersion) can be used to validate NCNames.<br />

Method equals(Object)<br />

final boolean equals(java.lang.Object objectToTest);<br />

Parameters<br />

objectToTest<br />

returns<br />

the Object to test <strong>for</strong> equality with this QName<br />

true if the given Object is equal to this QName else false<br />

Test this QName <strong>for</strong> equality with another Object.<br />

If the Object to be tested is not a QName or is null, then this method returns false.<br />

Two QNames are considered equal if and only if both the Namespace URI and local part are equal. This method uses<br />

String.equals() to check equality of the Namespace URI and local part. The prefix is NOT used to determine<br />

equality.<br />

This method satisfies the general contract of Object.equals(Object)<br />

Method getLocalPart()<br />

public String getLocalPart();<br />

Get the local part of this QName.<br />

Method getNamespaceURI()<br />

public String getNamespaceURI();<br />

Get the Namespace URI of this QName.<br />

Method getPrefix()<br />

public String getPrefix();<br />

Get the prefix of this QName.<br />

The prefix assigned to a QName might NOT be valid in a different context. For example, a QName may be assigned a<br />

prefix in the context of parsing a document but that prefix may be invalid in the context of a different document.<br />

Method hashCode()<br />

final int hashCode();<br />

Generate the hash code <strong>for</strong> this QName.<br />

120


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

The hash code is calculated using both the Namespace URI and the local part of the QName. The prefix is NOT used<br />

to calculate the hash code.<br />

This method satisfies the general contract of Object.hashCode().<br />

Method toString()<br />

public String toString();<br />

String representation of this QName.<br />

The commonly accepted way of representing a QName as a String was defined [http://jclark.com/xml/xmlns.htm]<br />

by James Clark. Although this is not a standard specification, it is in common use, e.g. javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>mer#setParameter(String name, Object value). This implementation represents a QName as: "{" + Namespace URI<br />

+ "}" + local part. If the Namespace URI .equals(<strong>XML</strong>Constants.NULL_NS_URI), only the local part is returned.<br />

An appropriate use of this method is <strong>for</strong> debugging or logging <strong>for</strong> human consumption.<br />

Note the prefix value is NOT returned as part of the String representation.<br />

This method satisfies the general contract of Object.toString().<br />

Method valueOf(String)<br />

static QName valueOf(java.lang.String qNameAsString);<br />

Parameters<br />

qNameAsString<br />

returns<br />

See Also<br />

String representation of the QName<br />

QName corresponding to the given String<br />

QName.toString() [Method toString()]<br />

QName derived from parsing the <strong>for</strong>matted String.<br />

If the String is null or does not con<strong>for</strong>m to QName.toString() [ Method toString()] <strong>for</strong>matting, an IllegalAr<br />

gumentException is thrown.<br />

The StringMUST be in the <strong>for</strong>m returned by QName.toString() [Method toString()].<br />

The commonly accepted way of representing a QName as a String was defined [http://jclark.com/xml/xmlns.htm]<br />

by James Clark. Although this is not a standard specification, it is in common use, e.g. javax.xml.trans<strong>for</strong>m.Trans<br />

<strong>for</strong>mer#setParameter(String name, Object value). This implementation parses a String <strong>for</strong>matted as: "{" + Namespace<br />

URI + "}" + local part. If the Namespace URI .equals(<strong>XML</strong>Constants.NULL_NS_URI), only the local part<br />

should be provided.<br />

The prefix value CANNOT be represented in the String and will be set to <strong>XML</strong>Constants.DEFAULT_NS_PREFIX.<br />

This method does not do full validation of the resulting QName.<br />

The Namespace URI is not validated as a URI reference [http://www.ietf.org/rfc/rfc2396.txt]. The local part is not<br />

validated as a NCName [http://www.w3.org/TR/REC-xml-names/#NT-NCName] as specified in Namespaces in <strong>XML</strong><br />

[http://www.w3.org/TR/REC-xml-names/]. <strong>XML</strong>Utils.isValidNCName(NCName) and <strong>XML</strong>Utils.isValidNCName(nc<br />

Name, xmlVersion) can be used to validate NCNames.<br />

121


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

Interface NamespaceContext<br />

Interface <strong>for</strong> read only <strong>XML</strong> Namespace context processing.<br />

An <strong>XML</strong> Namespace has the properties:<br />

• Namespace URI: Namespace name expressed as a URI to which the prefix is bound<br />

• prefix: syntactically, this is the part of the attribute name following the <strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIBUTE<br />

("xmlns") in the Namespace declaration<br />

example: <br />

All get*(*) methods operate in the current scope <strong>for</strong> Namespace URI and prefix resolution.<br />

Note that a Namespace URI can be bound to multiple prefixes in the current scope. This can occur when multiple XM<br />

LConstants.<strong>XML</strong>NS_ATTRIBUTE ("xmlns") Namespace declarations occur in the same Start-Tag and refer to the<br />

same Namespace URI. e.g.<br />

<br />

This can also occur when the same Namespace URI is used in multiple <strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIBUTE<br />

("xmlns") Namespace declarations in the logical parent element hierarchy. e.g.<br />

<br />

<br />

...<br />

<br />

<br />

Synopsis<br />

A prefix can only be bound to a single Namespace URI in the current scope.<br />

implements public NamespaceContext {<br />

public String getNamespaceURI(java.lang.String prefix);<br />

public String getPrefix(java.lang.String namespaceURI);<br />

public Iterator getPrefixes(java.lang.String namespaceURI);<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

122


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

Version $Revision: 1.4 $, $Date: 2003/12/06 00:21:40 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

javax.<strong>XML</strong>Constants <strong>for</strong> declarations of common <strong>XML</strong> values, <strong>XML</strong> Schema Part2: Datatypes<br />

[http://www.w3.org/TR/xmlschema-2/#QName], Namespaces in <strong>XML</strong><br />

[http://www.w3.org/TR/REC-xml-names/#ns-qualnames], Namespaces in <strong>XML</strong> Errata<br />

[http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

javax.xml.namespace.NamespaceContext<br />

Members<br />

Method getNamespaceURI(String)<br />

public String getNamespaceURI(java.lang.String prefix);<br />

Parameters<br />

prefix<br />

returns<br />

prefix to look up<br />

Namespace URI bound to prefix in the current scope<br />

Get Namespace URI bound to a prefix in the current scope.<br />

When requesting a Namespace URI by prefix, the following table describes the returned Namespace URI value <strong>for</strong> all<br />

possible prefix values:<br />

getNamespaceURI(prefix) return value <strong>for</strong> specified prefixes<br />

prefix parameter<br />

DEFAULT_NS_PREFIX ("")<br />

bound prefix<br />

unbound prefix<br />

Namespace URI return value<br />

default Namespace URI in the current<br />

scope or <strong>XML</strong>Con<br />

stants.NULL_NS_URI("") when<br />

there is no default Namespace URI in<br />

the current scope<br />

Namespace URI bound to prefix in<br />

current scope<br />

X M L C o n<br />

stants.NULL_NS_URI("")<br />

<strong>XML</strong>Constants.<strong>XML</strong>_NS_PREFIX <strong>XML</strong>Constants.<strong>XML</strong>_NS_URI<br />

("xml")<br />

( " h t<br />

tp://www.w3.org/<strong>XML</strong>/1998/namespace")<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE ("xmlns")<br />

null<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE_NS_URI ("ht<br />

tp://www.w3.org/2000/xmlns/")<br />

IllegalArgumentException is<br />

thrown<br />

123


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

Method getPrefix(String)<br />

public String getPrefix(java.lang.String namespaceURI);<br />

Parameters<br />

namespaceURI<br />

returns<br />

URI of Namespace to lookup<br />

prefix bound to Namespace URI in current context<br />

Get prefix bound to Namespace URI in the current scope.<br />

To get all prefixes bound to a Namespace URI in the current scope, use javax.xml.namespace.NamespaceContext.get<br />

Prefixes [ Method getPrefixes(java.lang.String)].<br />

When requesting a prefix by Namespace URI, the following table describes the returned prefix value <strong>for</strong> all Namespace<br />

URI values:<br />

getPrefix(namespaceURI) return value <strong>for</strong> specified Namespace<br />

URIs<br />

Namespace URI parameter<br />

<br />

bound Namespace URI<br />

unbound Namespace URI<br />

<strong>XML</strong>Constants.<strong>XML</strong>_NS_URI<br />

( " h t<br />

tp://www.w3.org/<strong>XML</strong>/1998/namespace")<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE_NS_URI ("ht<br />

tp://www.w3.org/2000/xmlns/")<br />

null<br />

Method getPrefixes(String)<br />

prefix value returned<br />

<strong>XML</strong>Constants.DE<br />

FAULT_NS_PREFIX ("")<br />

prefix bound to Namespace URI in the<br />

current scope, if multiple prefixes are<br />

bound to the Namespace URI in the<br />

current scope, a single arbitrary prefix,<br />

whose choice is implementation de<br />

pendent, is returned<br />

null<br />

<strong>XML</strong>Constants.<strong>XML</strong>_NS_PREFIX<br />

("xml")<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE ("xmlns")<br />

IllegalArgumentException is<br />

thrown<br />

public Iterator getPrefixes(java.lang.String namespaceURI);<br />

Parameters<br />

namespaceURI<br />

returns<br />

URI of Namespace to lookup<br />

Iterator <strong>for</strong> all prefixes bound to the Namespace URI in the current scope<br />

Get all prefixes bound to a Namespace URI in the current scope.<br />

124


Community Draft<br />

Package javax.xml.namespace<br />

Community Draft<br />

An Iterator over String elements is returned in an arbitrary, implementation dependent, order.<br />

The Iterator is not modifiable. e.g. the remove() method will throw UnsupportedOperationException.<br />

When requesting prefixes by Namespace URI, the following table describes the returned prefixes value <strong>for</strong> all Namespace<br />

URI values:<br />

getPrefixes(namespaceURI) return value <strong>for</strong> specified Namespace<br />

URIs<br />

Namespace URI parameter<br />

bound Namespace URI, including the<br />

<br />

unbound Namespace URI<br />

<strong>XML</strong>Constants.<strong>XML</strong>_NS_URI<br />

( " h t<br />

tp://www.w3.org/<strong>XML</strong>/1998/namespace")<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE_NS_URI ("ht<br />

tp://www.w3.org/2000/xmlns/")<br />

null<br />

prefixes value returned<br />

Iterator over prefixes bound to<br />

Namespace URI in the current scope<br />

in an arbitrary, implementation depend<br />

ent, order<br />

empty Iterator<br />

Iterator with one element set to<br />

<strong>XML</strong>Constants.<strong>XML</strong>_NS_PREFIX<br />

("xml")<br />

Iterator with one element set to<br />

<strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIB<br />

UTE ("xmlns")<br />

IllegalArgumentException is<br />

thrown<br />

125


Community Draft<br />

Community Draft<br />

Chapter 14. Package javax.xml.xpath<br />

XPath <strong>API</strong> <strong>for</strong> XPath 1.0.<br />

<strong>API</strong> provides access to the XPath evaluation environment and expression results independent of the underlying data<br />

object model.<br />

The following <strong>XML</strong> standards apply:<br />

• <strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath]<br />

About XPath<br />

The XPath language provides a simple, concise syntax <strong>for</strong> accessing individual parts of an <strong>XML</strong> document. XPath is<br />

a W3C-defined language and an official W3C recommendation; the W3C hosts the <strong>XML</strong> Path Language (XPath)<br />

Version 1.0 specification. XPath started in life in 1999 as a supplement to the XSLT and XPointer languages, but has<br />

more recently become popular as a stand-alone language.<br />

The <strong>Java</strong> XPath <strong>API</strong> evaluates expressions and returns one of five types:<br />

• Node<br />

• NodeList (an unordered collection of nodes without duplicates)<br />

• Boolean<br />

• Double<br />

• String<br />

The type returned is determined by both the type of expression and a value passed to the XPath object.<br />

XPath Examples<br />

Given the following sample <strong>XML</strong> document:<br />

<br />

<br />

<br />

<br />

green<br />

<br />

<br />

the subsequent table shows examples <strong>for</strong> per<strong>for</strong>ming common tasks with XPath in the context of the sample document.<br />

126


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

XPath Expression<br />

/<br />

/widgets/widget<br />

//*<br />

//widgets<br />

Description<br />

selects the document's root element<br />

selects all of the children of the root<br />

element with an element<br />

name <br />

selects all of the elements in the docu<br />

ment; the document hierarchy will be<br />

flattened<br />

selects all elements named <br />

anywhere they occur in the document<br />

/widgets/widget[@name="c"] selects the child of the root<br />

element that contains an<br />

attribute "name" with the value "c";<br />

note that the child of the<br />

is not returned<br />

//widget[@name="c"]/style<br />

Using the XPath <strong>API</strong><br />

selects the element with a<br />

parent element containing<br />

an attribute "name" with the value "c"<br />

As stated earlier, the evaluation of XPath expressions can return their results as one of five types: Node, NodeList,<br />

Boolean, Double, and String. It is not the syntax of the expression that determines the result type, but the context<br />

in which it is evaluated.<br />

To illustrate how different types may be used with the same expression, consider the evaluation of the following XPath<br />

expression against the sample document above:<br />

/widgets/widget[@name="a"]/@quantity<br />

The expression above selects the value of the "quantity" attribute on a child of that contains<br />

an attribute "name" set to a value of "a". Because of value of "quantity" is 6, it can be evaluated as either a String<br />

or a Double. The following code evaluates the expression as a Double:<br />

// parse the <strong>XML</strong> as a W3C Document<br />

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();<br />

org.w3c.Document document = builder.parse(new File("/widgets.xml"));<br />

// evaluate the XPath expression against the Document<br />

XPath xpath = XPathFactory.newInstance().newXPath();<br />

String expression = "/widgets/widget[@name='a']/@quantity";<br />

Double quantity = (Double) xpath.evaluate(expression, document, XPathConstants.NUMBE<br />

The third argument of the XPath.evaluate method in the example above specifies that the result of the evaluation<br />

should be a Double, which is the <strong>Java</strong> implementation of the XPath Number type. To evaluate the same expression<br />

as a String, the third argument must be changed thusly:<br />

127


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

String quantity = (String) xpath.evaluate(expression, document,<br />

XPathConstants.STRING);<br />

Because the W3C DOM <strong>API</strong> (and thus the <strong>JAXP</strong> <strong>API</strong>) models element attributes as nodes, the same attribute value<br />

can also be evaluated as a Node, as shown:<br />

Node quantity = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);<br />

Attr attr = (Attr) quantity;<br />

Finally, each expression can be evaluated as a Boolean to indicate whether or not the expression was successful in<br />

evaluating to any result. This too is shown:<br />

Boolean result = (Boolean) xpath.evaluate(expression, document,<br />

XPathConstants.BOOLEAN);<br />

Note that when the third argument is left off of the XPath.evaluate method, all expressions are evaluated to a<br />

String value.<br />

Additional In<strong>for</strong>mation<br />

There's much more to XPath than we've discussed here. For more in<strong>for</strong>mation, you may read the W3C XPath specific<br />

ation [http://www.w3.org/TR/xpath], or refer to one of the many books on the subject. The default implement of this<br />

interface provides an XPath evaluation engine fully compliant with the W3C specification.<br />

• @author Ben Galbraith [mailto:Ben@galbraiths.org]<br />

• @author Norm Walsh [mailto:Norman.Walsh@Sun.com]<br />

• @author Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

• @version $Revision: 1.6 $, $Date: 2003/12/10 17:47:45 $<br />

• @see <strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath]<br />

• @since 1.5<br />

Class XPathConstants<br />

Synopsis<br />

XPath constants.<br />

}<br />

public XPathConstants {<br />

final String toString();<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.COM], Jeff Suttor [mailto:Jeff.Suttor@Sun.COM]<br />

128


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Version $Revision: 1.6 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

<strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath]<br />

java.lang.Object<br />

|<br />

javax.xml.xpath.XPathConstants<br />

Members<br />

Field BOOLEAN<br />

static javax.xml.namespace.QName BOOLEAN ;<br />

The XPath 1.0 boolean data type.<br />

Field DOM_OBJECT_MODEL<br />

Field NODE<br />

static java.lang.String DOM_OBJECT_MODEL ;<br />

The URI <strong>for</strong> the DOM object model, "http://java.sun.com/jaxp/xpath/dom".<br />

static javax.xml.namespace.QName NODE ;<br />

The XPath 1.0 NodeSet data type.<br />

Field NODESET<br />

static javax.xml.namespace.QName NODESET ;<br />

The XPath 1.0 NodeSet data type.<br />

Field NUMBER<br />

static javax.xml.namespace.QName NUMBER ;<br />

The XPath 1.0 number data type.<br />

Field STRING<br />

static javax.xml.namespace.QName STRING ;<br />

The XPath 1.0 string data type.<br />

Method toString()<br />

final String toString();<br />

129


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Human readable String of all XPathConstants public fields.<br />

This method satisfies the general contract of java.lang.Object.toString.<br />

Class XPathFactory<br />

Synopsis<br />

XPathFactory provides instances of XPaths.<br />

}<br />

public XPathFactory {<br />

protected XPathFactory();<br />

static XPathFactory newInstance()<br />

throws XPathFactoryConfigurationException;<br />

static XPathFactory newInstance(java.lang.String uri)<br />

throws XPathFactoryConfigurationException;<br />

public XPath abstract newXPath();<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/08 04:40:47 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.xpath.XPathFactory<br />

Members<br />

Constructor XPathFactory()<br />

protected XPathFactory();<br />

Protected constructor as javax.xml.xpath.XPathFactory.newInstance [ Method newInstance()] or<br />

javax.xml.xpath.XPathFactory.newInstance [ Method newInstance(java.lang.String)] should be used to create a new<br />

instance of an XPathFactory.<br />

Method newInstance()<br />

static XPathFactory newInstance()<br />

throws XPathFactoryConfigurationException;<br />

130


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Exceptions<br />

XPathFactoryConfigura<br />

tionException<br />

If the default object model is unavailable.<br />

Get a new XPathFactory instance using the default object model.<br />

Method newInstance(String)<br />

static XPathFactory newInstance(java.lang.String uri)<br />

throws XPathFactoryConfigurationException;<br />

Parameters<br />

uri<br />

returns<br />

Identifies the underlying object model.<br />

New instance of an XPathFactory.<br />

Exceptions<br />

XPathFactoryConfigura<br />

tionException<br />

NullPointerException<br />

If the specified object model is unavailable.<br />

If uri is null.<br />

Get a new XPathFactory instance using the specified object model.<br />

A NullPointerException is thrown if uri is null.<br />

Method newXPath()<br />

public XPath abstract newXPath();<br />

Return a new XPath using the underlying object model determined when the XPathFactory was instantiated.<br />

Interface XPath<br />

XPath provides access to the XPath evaluation environment and expressions.<br />

Evaluation of XPath Expressions.<br />

context<br />

variables<br />

If a request is made to evaluate the expression in the ab<br />

sence of a context item, simple expressions, such as "1+1",<br />

can be evaluated. Any expression that refers to the context<br />

will throw an javax.xml.xpath.XPathExpressionException<br />

[Exception XPathExpressionException].<br />

If the expression contains a variable reference, its value<br />

will be found through the javax.xml.xpath.XPathVari<br />

ableResolver [Interface XPathVariableResolver] set with<br />

javax.xml.xpath.XPath.setXPathVariableResolver [Method<br />

setXPathVariableResolver(javax.xml.xpath.XPathVari<br />

ableResolver)]. An javax.xml.xpath.XPathExpressionEx<br />

ception [Exception XPathExpressionException] is raised<br />

131


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Evaluation of XPath Expressions.<br />

functions<br />

QNames<br />

result<br />

if the variable resolver is undefined or the resolver returns<br />

null <strong>for</strong> the variable. The value of a variable must be<br />

immutable through the course of any single evaluation.<br />

If the expression contains a function reference, the function<br />

will be found through the javax.xml.xpath.XPathFunction<br />

Resolver [Interface XPathFunctionResolver] set with<br />

javax.xml.xpath.XPath.setXPathFunctionResolver<br />

[Method<br />

setXPathFunctionResolv<br />

er(javax.xml.xpath.XPathFunctionResolver)]. An<br />

javax.xml.xpath.XPathExpressionException [Exception<br />

XPathExpressionException] is raised if the function resolv<br />

er is undefined or the function resolver returns null <strong>for</strong><br />

the function.<br />

QNames in the expression are resolved against the XPath<br />

namespace context set with javax.xml.xpath.XPath.set<br />

NamespaceContext [Method setNamespaceCon<br />

text(javax.xml.namespace.NamespaceContext)].<br />

This result of evaluating an expression is converted to an<br />

instance of the desired return type. Valid return types are<br />

defined in javax.xml.xpath.XPathConstants [Class<br />

XPathConstants]. Conversion to the return type follows<br />

XPath conversion rules.<br />

Synopsis<br />

implements public XPath {<br />

public void setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver resolver);<br />

public XPathVariableResolver getXPathVariableResolver();<br />

public void setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver resolver);<br />

public XPathFunctionResolver getXPathFunctionResolver();<br />

public void setNamespaceContext(javax.xml.namespace.NamespaceContext nsContext);<br />

public NamespaceContext getNamespaceContext();<br />

public XPathExpression compile(java.lang.String expression)<br />

throws XPathExpressionException;<br />

public Object evaluate(java.lang.String expression,<br />

java.lang.Object item,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(java.lang.String expression,<br />

java.lang.Object item)<br />

throws XPathExpressionException;<br />

132


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

public Object evaluate(java.lang.String expression,<br />

java.net.URL documentURL,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(java.lang.String expression,<br />

java.net.URL documentURL)<br />

throws XPathExpressionException;<br />

public Object evaluate(java.lang.String expression,<br />

org.xml.sax.InputSource source,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(java.lang.String expression,<br />

org.xml.sax.InputSource source)<br />

throws XPathExpressionException;<br />

}<br />

Author<br />

Norman Walsh [Norman.Walsh@Sun.com], Jeff Suttor [Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.11 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

<strong>XML</strong> Path Language (XPath) Version 1.0 [http://www.w3.org/TR/xpath]<br />

javax.xml.xpath.XPath<br />

Members<br />

Method compile(String)<br />

public XPathExpression compile(java.lang.String expression)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

returns<br />

The XPath expression.<br />

Compiled XPath expression.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If expression cannot be compiled.<br />

If expression is null.<br />

Compile an XPath expression <strong>for</strong> later evaluation.<br />

If expression is null, a NullPointerException is thrown.<br />

133


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Method evaluate(String, InputSource)<br />

public String evaluate(java.lang.String expression,<br />

org.xml.sax.InputSource source)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

source<br />

returns<br />

The XPath expression.<br />

The InputSource of the document to evaluate over.<br />

The String that is the result of evaluating the expression and converting the result to a<br />

String.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If expression cannot be evaluated.<br />

If expression or source is null.<br />

Evaluate an XPath expression in the context of the specified InputSource and return the result as a String.<br />

This method calls javax.xml.xpath.XPath.evaluate [ Method evaluate(java.lang.String, org.xml.sax.InputSource,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

If expression or source is null, then a NullPointerException is thrown.<br />

Method evaluate(String, InputSource, QName)<br />

public Object evaluate(java.lang.String expression,<br />

org.xml.sax.InputSource source,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

source<br />

returnType<br />

returns<br />

The XPath expression.<br />

The input source of the document to evaluate over.<br />

The desired return type.<br />

The Object that encapsulates the result of evaluating the expression.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If expression cannot be evaluated.<br />

134


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If expression, source or returnType is null.<br />

Evaluate an XPath expression in the context of the specified InputSource and return the result as the specified<br />

type.<br />

This method builds a data model <strong>for</strong> the org.xml.sax.InputSource and calls javax.xml.xpath.XPath.evaluate [ Method<br />

evaluate(java.lang.String, java.lang.Object, javax.xml.namespace.QName)] on the resulting document object.<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

If expression, source or returnType is null, then a NullPointerException is thrown.<br />

Method evaluate(String, Object)<br />

public String evaluate(java.lang.String expression,<br />

java.lang.Object item)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

item<br />

returns<br />

The XPath expression.<br />

The starting context (node or node list, <strong>for</strong> example).<br />

The String that is the result of evaluating the expression and converting the result to a<br />

String.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If expression cannot be evaluated.<br />

If expression is null.<br />

Evaluate an XPath expression in the specified context and return the result as a String.<br />

This method calls javax.xml.xpath.XPath.evaluate [ Method evaluate(java.lang.String, java.lang.Object,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

A null value <strong>for</strong> item indicates that the expression should be evaluated without a context. If expression is null,<br />

then a NullPointerException is thrown.<br />

135


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Method evaluate(String, Object, QName)<br />

public Object evaluate(java.lang.String expression,<br />

java.lang.Object item,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

item<br />

returnType<br />

returns<br />

The XPath expression.<br />

The starting context (node or node list, <strong>for</strong> example).<br />

The desired return type.<br />

Result of evaluating an XPath expression as an Object of returnType.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If expression cannot be evaluated.<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If expression or returnType is null.<br />

Evaluate an XPath expression in the specified context and return the result as the specified type.<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

A null value <strong>for</strong> item indicates that the expression should be evaluated without a context. If expression or re<br />

turnType is null, then a NullPointerException is thrown.<br />

Method evaluate(String, URL)<br />

public String evaluate(java.lang.String expression,<br />

java.net.URL documentURL)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

documentURL<br />

returns<br />

The XPath expression.<br />

The URL of the document to evaluate over.<br />

The String that is the result of evaluating the expression and converting the result to a<br />

String.<br />

136


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If expression cannot be evaluated.<br />

If expression or documentURL is null.<br />

Evaluate an XPath expression in the context of the specified document and return the result as a String.<br />

This method calls javax.xml.xpath.XPath.evaluate [ Method evaluate(java.lang.String, java.net.URL,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

If expression or documentURL is null, then a NullPointerException is thrown.<br />

Method evaluate(String, URL, QName)<br />

public Object evaluate(java.lang.String expression,<br />

java.net.URL documentURL,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

expression<br />

documentURL<br />

returnType<br />

returns<br />

The XPath expression.<br />

The URL of the document to evaluate over.<br />

The desired return type.<br />

The Object that encapsulates the result of evaluating the expression.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If expression cannot be evaluated.<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If expression, documentURL or returnType is null.<br />

Evaluate an XPath expression in the context of the specified document and return the result as the specified type.<br />

This method builds a data model <strong>for</strong> the document identified by the URL and calls javax.xml.xpath.XPath.evaluate [<br />

Method evaluate(java.lang.String, java.lang.Object, javax.xml.namespace.QName)] on the resulting document object.<br />

See Evaluation of XPath Expressions [#XPath-evaluation] <strong>for</strong> context item evaluation, variable, function and QName<br />

resolution and return type conversion.<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

If expression, documentURL or returnType is null, then a NullPointerException is thrown.<br />

137


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Method getNamespaceContext()<br />

public NamespaceContext getNamespaceContext();<br />

Return the current namespace context.<br />

null is returned in no namespace context is in effect.<br />

Method getXPathFunctionResolver()<br />

public XPathFunctionResolver getXPathFunctionResolver();<br />

Return the current function resolver.<br />

null is returned in no function resolver is in effect.<br />

Method getXPathVariableResolver()<br />

public XPathVariableResolver getXPathVariableResolver();<br />

Return the current variable resolver.<br />

null is returned in no variable resolver is in effect.<br />

Method setNamespaceContext(NamespaceContext)<br />

public void setNamespaceContext(javax.xml.namespace.NamespaceContext nsContext);<br />

Parameters<br />

nsContext<br />

Namespace context to use.<br />

Exceptions<br />

NullPointerException<br />

If nsContext is null.<br />

Establish a namespace context.<br />

A NullPointerException is thrown if nsContext is null.<br />

Method setXPathFunctionResolver(XPathFunctionResolver)<br />

public void setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver resolver);<br />

Parameters<br />

resolver<br />

XPath function resolver.<br />

Exceptions<br />

NullPointerException<br />

If resolver is null.<br />

Establish a function resolver.<br />

138


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

A NullPointerException is thrown if resolver is null.<br />

Method setXPathVariableResolver(XPathVariableResolver)<br />

public void setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver resolver);<br />

Parameters<br />

resolver<br />

Variable resolver.<br />

Exceptions<br />

NullPointerException<br />

If resolver is null.<br />

Establish a variable resolver.<br />

A NullPointerException is thrown if resolver is null.<br />

Interface XPathExpression<br />

XPathExpression provides access to compiled XPath expressions.<br />

Evaluation of XPath Expressions.<br />

context<br />

variables<br />

functions<br />

QNames<br />

result<br />

If a request is made to evaluate the expression in the ab<br />

sence of a context item, simple expressions, such as "1+1",<br />

can be evaluated. Any expression that refers to the context<br />

will throw an javax.xml.xpath.XPathExpressionException<br />

[Exception XPathExpressionException].<br />

If the expression contains a variable reference, its value<br />

will be found through the javax.xml.xpath.XPathVari<br />

ableResolver [Interface XPathVariableResolver]. An<br />

javax.xml.xpath.XPathExpressionException [Exception<br />

XPathExpressionException] is raised if the variable resolv<br />

er is undefined or the resolver returns null <strong>for</strong> the vari<br />

able. The value of a variable must be immutable through<br />

the course of any single evaluation.<br />

If the expression contains a function reference, the function<br />

will be found through the javax.xml.xpath.XPathFunction<br />

Resolver [Interface XPathFunctionResolver]. An<br />

javax.xml.xpath.XPathExpressionException [Exception<br />

XPathExpressionException] is raised if the function resolv<br />

er is undefined or the function resolver returns null <strong>for</strong><br />

the function.<br />

QNames in the expression are resolved against the XPath<br />

namespace context.<br />

This result of evaluating an expression is converted to an<br />

instance of the desired return type. Valid return types are<br />

defined in javax.xml.xpath.XPathConstants [Class<br />

XPathConstants]. Conversion to the return type follows<br />

XPath conversion rules.<br />

139


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Synopsis<br />

implements public XPathExpression {<br />

}<br />

public Object evaluate(java.lang.Object item,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(java.lang.Object item)<br />

throws XPathExpressionException;<br />

public Object evaluate(java.net.URL documentURL,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(java.net.URL documentURL)<br />

throws XPathExpressionException;<br />

public Object evaluate(org.xml.sax.InputSource source,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

public String evaluate(org.xml.sax.InputSource source)<br />

throws XPathExpressionException;<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

See Also <strong>XML</strong> Path Language (XPath) Version 1.0, Expressions<br />

[http://www.w3.org/TR/xpath#section-Expressions]<br />

Inheritance Path<br />

javax.xml.xpath.XPathExpression<br />

Members<br />

Method evaluate(InputSource)<br />

public String evaluate(org.xml.sax.InputSource source)<br />

throws XPathExpressionException;<br />

Parameters<br />

source<br />

returns<br />

The InputSource of the document to evaluate over.<br />

The String that is the result of evaluating the expression and converting the result to a String.<br />

140


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If the expression cannot be evaluated.<br />

If source is null.<br />

Evaluate the compiled XPath expression in the context of the specified InputSource and return the result as a<br />

String.<br />

This method calls javax.xml.xpath.XPathExpression.evaluate [ Method evaluate(org.xml.sax.InputSource,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

If source is null, then a NullPointerException is thrown.<br />

Method evaluate(InputSource, QName)<br />

public Object evaluate(org.xml.sax.InputSource source,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

source<br />

returnType<br />

returns<br />

The InputSource of the document to evaluate over.<br />

The desired return type.<br />

The Object that is the result of evaluating the expression and converting the result to re<br />

turnType.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If the expression cannot be evaluated.<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If source or returnType is null.<br />

Evaluate the compiled XPath expression in the context of the specified InputSource and return the result as the<br />

specified type.<br />

This method builds a data model <strong>for</strong> the org.xml.sax.InputSource and calls javax.xml.xpath.XPathExpression.evaluate<br />

[ Method evaluate(java.lang.Object, javax.xml.namespace.QName)] on the resulting document object.<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

If source or returnType is null, then a NullPointerException is thrown.<br />

141


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Method evaluate(Object)<br />

public String evaluate(java.lang.Object item)<br />

throws XPathExpressionException;<br />

Parameters<br />

item<br />

returns<br />

The starting context (node or node list, <strong>for</strong> example).<br />

The String that is the result of evaluating the expression and converting the result to a String.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If the expression cannot be evaluated.<br />

Evaluate the compiled XPath expression in the specified context and return the result as a String.<br />

This method calls javax.xml.xpath.XPathExpression.evaluate [ Method evaluate(java.lang.Object,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

A null value <strong>for</strong> item indicates that the expression should be evaluated without a context.<br />

Method evaluate(Object, QName)<br />

public Object evaluate(java.lang.Object item,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

item<br />

returnType<br />

returns<br />

The starting context (node or node list, <strong>for</strong> example).<br />

The desired return type.<br />

The Object that is the result of evaluating the expression and converting the result to re<br />

turnType.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If the expression cannot be evaluated.<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If returnType is null.<br />

Evaluate the compiled XPath expression in the specified context and return the result as the specified type.<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

142


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

A null value <strong>for</strong> item indicates that the expression should be evaluated without a context. If returnType is null,<br />

then a NullPointerException is thrown.<br />

Method evaluate(URL)<br />

public String evaluate(java.net.URL documentURL)<br />

throws XPathExpressionException;<br />

Parameters<br />

documentURL<br />

returns<br />

The URL of the document to evaluate over.<br />

The String that is the result of evaluating the expression and converting the result to a<br />

String.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

NullPointerException<br />

If the expression cannot be evaluated.<br />

If documentURL is null.<br />

Evaluate the compiled XPath expression in the context of the specified document and return the result as a String.<br />

This method calls javax.xml.xpath.XPathExpression.evaluate [ Method evaluate(java.net.URL,<br />

javax.xml.namespace.QName)] with a returnType of javax.xml.xpath.XPathConstants.STRING [ Field STRING].<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

If documentURL is null, then a NullPointerException is thrown.<br />

Method evaluate(URL, QName)<br />

public Object evaluate(java.net.URL documentURL,<br />

javax.xml.namespace.QName returnType)<br />

throws XPathExpressionException;<br />

Parameters<br />

documentURL<br />

returnType<br />

returns<br />

The URL of the document to evaluate over.<br />

The desired return type.<br />

The Object that is the result of evaluating the expression and converting the result to<br />

returnType.<br />

Exceptions<br />

XPathExpressionExcep<br />

tion<br />

If the expression cannot be evaluated.<br />

143


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

IllegalArgumentException If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [<br />

Class XPathConstants].<br />

NullPointerException<br />

If documentURL or returnType is null.<br />

Evaluate the compiled XPath expression in the context of the specified document and return the result as the specified<br />

type.<br />

This method builds a data model <strong>for</strong> the document identified by the java.net.URL and calls javax.xml.xpath.XPathEx<br />

pression.evaluate [ Method evaluate(java.lang.Object, javax.xml.namespace.QName)] on the resulting document object.<br />

See Evaluation of XPath Expressions [#XPathExpression-evaluation] <strong>for</strong> context item evaluation, variable, function<br />

and QName resolution and return type conversion.<br />

If returnType is not one of the types defined in javax.xml.xpath.XPathConstants [ Class XPathConstants], then an<br />

IllegalArgumentException is thrown.<br />

If documentURL or returnType is null, then a NullPointerException is thrown.<br />

Interface XPathFunction<br />

Synopsis<br />

XPathFunction provides access to XPath functions.<br />

Functions are identified by QName and arity in XPath.<br />

implements public XPathFunction {<br />

}<br />

public Object evaluate(java.util.List args)<br />

throws XPathFunctionException;<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

Inheritance Path<br />

javax.xml.xpath.XPathFunction<br />

Members<br />

Method evaluate(List)<br />

public Object evaluate(java.util.List args)<br />

throws XPathFunctionException;<br />

Parameters<br />

args<br />

The arguments, null is a valid value.<br />

144


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

returns<br />

Exceptions<br />

The result of evaluating the XPath function as an Object.<br />

XPathFunctionException<br />

If args cannot be evaluated with this XPath function.<br />

Evaluate the function with the specified arguments.<br />

Interface XPathFunctionResolver<br />

Synopsis<br />

XPathFunctionResolver provides access to the set of user defined XPathFunctions.<br />

XPath functions are resolved by name and arity. The resolver is not needed <strong>for</strong> XPath built-in functions and the resolver<br />

cannot be used to override those functions.<br />

implements public XPathFunctionResolver {<br />

}<br />

public XPathFunction resolveFunction(javax.xml.namespace.QName functionName,<br />

int arity);<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.6 $, $Date: 2003/12/08 04:40:47 $<br />

Since 1.5<br />

See Also <strong>XML</strong> Path Language (XPath) Version 1.0, Core Function Library<br />

[http://www.w3.org/TR/xpath#corelib]<br />

Inheritance Path<br />

javax.xml.xpath.XPathFunctionResolver<br />

Members<br />

Method resolveFunction(QName, int)<br />

public XPathFunction resolveFunction(javax.xml.namespace.QName functionName,<br />

int arity);<br />

Parameters<br />

functionName<br />

arity<br />

returns<br />

The function name.<br />

The number of arguments that the returned function must accept.<br />

The function or null if no function named functionName with arity arguments<br />

exists.<br />

145


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Exceptions<br />

NullPointerException<br />

If functionName or arity is null.<br />

Find a function in the set of available functions.<br />

If functionName or arity is null, then a NullPointerException is thrown.<br />

Interface XPathVariableResolver<br />

Synopsis<br />

XPathVariableResolver provides access to the set of user defined XPath variables.<br />

The XPathVariableResolver and the XPath evaluator must adhere to a contract that cannot be directly en<strong>for</strong>ced<br />

by the <strong>API</strong>. Although variables may be mutable, that is, an application may wish to evaluate the same XPath expression<br />

more than once with different variable values, in the course of evaluating any single XPath expression, a variable's<br />

value must be immutable.<br />

implements public XPathVariableResolver {<br />

}<br />

public Object resolveVariable(javax.xml.namespace.QName variableName);<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.6 $, $Date: 2003/12/08 04:40:47 $<br />

Since 1.5<br />

Inheritance Path<br />

javax.xml.xpath.XPathVariableResolver<br />

Members<br />

Method resolveVariable(QName)<br />

public Object resolveVariable(javax.xml.namespace.QName variableName);<br />

Parameters<br />

variableName<br />

returns<br />

The QName of the variable name.<br />

The variables value, or null if no variable named variableName exists. The value<br />

returned must be of a type appropriate <strong>for</strong> the underlying object model.<br />

Exceptions<br />

NullPointerException<br />

If variableName is null.<br />

Find a variable in the set of available variables.<br />

146


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

If variableName is null, then a NullPointerException is thrown.<br />

Exception XPathException<br />

Synopsis<br />

XPathException represents a generic XPath exception.<br />

}<br />

public XPathException extends Exception {<br />

public XPathException(java.lang.String message);<br />

public XPathException(java.lang.Exception cause);<br />

public XPathException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Author<br />

Norman Walsh [Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.COM]<br />

Version $Revision: 1.12 $, $Date: 2003/12/08 04:40:47 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.xpath.XPathException<br />

Members<br />

Constructor XPathException(Exception)<br />

public XPathException(java.lang.Exception cause);<br />

Parameters<br />

cause<br />

The cause.<br />

Exceptions<br />

NullPointerException<br />

if cause is null.<br />

Constructs a new XPathException with the specified cause.<br />

147


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

If cause is null, then a NullPointerException is thrown.<br />

Constructor XPathException(String)<br />

public XPathException(java.lang.String message);<br />

Parameters<br />

message<br />

The detail message.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathException with the specified detail message.<br />

The cause is not initialized.<br />

If message is null, then a NullPointerException is thrown.<br />

Constructor XPathException(String, Exception)<br />

public XPathException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Parameters<br />

message<br />

cause<br />

The detail message.<br />

The cause. A null value is permitted, and indicates that the cause is nonexistent or unknown.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathException with the specified detail message and cause.<br />

If message is null, then a NullPointerException is thrown.<br />

Exception XPathExpressionException<br />

Synopsis<br />

XPathExpressionException represents an error in an XPath expression.<br />

public XPathExpressionException extends XPathException {<br />

public XPathExpressionException(java.lang.String message);<br />

public XPathExpressionException(java.lang.Exception cause);<br />

public XPathExpressionException(java.lang.String message,<br />

java.lang.Exception cause);<br />

148


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

}<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.1 $, $Date: 2003/12/08 04:40:47 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.xpath.XPathException<br />

|<br />

javax.xml.xpath.XPathExpressionException<br />

Members<br />

Constructor XPathExpressionException(Exception)<br />

public XPathExpressionException(java.lang.Exception cause);<br />

Parameters<br />

cause<br />

The cause.<br />

Exceptions<br />

NullPointerException<br />

if cause is null.<br />

Constructs a new XPathExpressionException with the specified cause.<br />

If cause is null, then a NullPointerException is thrown.<br />

Constructor XPathExpressionException(String)<br />

public XPathExpressionException(java.lang.String message);<br />

Parameters<br />

message<br />

The detail message.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathExpressionException with the specified detail message.<br />

149


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

The cause is not initialized.<br />

If message is null, then a NullPointerException is thrown.<br />

Constructor XPathExpressionException(String, Exception)<br />

public XPathExpressionException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Parameters<br />

message<br />

cause<br />

The detail message.<br />

The cause. A null value is permitted, and indicates that the cause is nonexistent or unknown.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathExpressionException with the specified detail message and cause.<br />

If message is null, then a NullPointerException is thrown.<br />

Exception XPathFactoryConfigurationException<br />

Synopsis<br />

XPathFactoryConfigurationException represents a configuration error in a XPathFactory environment.<br />

}<br />

public XPathFactoryConfigurationException extends XPathException {<br />

public XPathFactoryConfigurationException(java.lang.String message);<br />

public XPathFactoryConfigurationException(java.lang.Exception cause);<br />

public XPathFactoryConfigurationException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.4 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

150


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Members<br />

Inheritance Path<br />

|<br />

javax.xml.xpath.XPathException<br />

|<br />

javax.xml.xpath.XPathFactoryConfigurationException<br />

Constructor XPathFactoryConfigurationException(Exception)<br />

public XPathFactoryConfigurationException(java.lang.Exception cause);<br />

Parameters<br />

cause<br />

The cause.<br />

Exceptions<br />

NullPointerException<br />

if cause is null.<br />

Constructs a new XPathFactoryConfigurationException with the specified cause.<br />

If cause is null, then a NullPointerException is thrown.<br />

Constructor XPathFactoryConfigurationException(String)<br />

public XPathFactoryConfigurationException(java.lang.String message);<br />

Parameters<br />

message<br />

The detail message.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathFactoryConfigurationException with the specified detail message.<br />

The cause is not initialized.<br />

If message is null, then a NullPointerException is thrown.<br />

Constructor XPathFactoryConfigurationException(String, Exception)<br />

public XPathFactoryConfigurationException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Parameters<br />

message<br />

cause<br />

The detail message.<br />

The cause. A null value is permitted, and indicates that the cause is nonexistent or unknown.<br />

151


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathFactoryConfigurationException with the specified detail message and cause.<br />

If message is null, then a NullPointerException is thrown.<br />

Exception XPathFunctionException<br />

Synopsis<br />

XPathFunctionException represents an error with an XPath function.<br />

}<br />

public XPathFunctionException extends XPathExpressionException {<br />

public XPathFunctionException(java.lang.String message);<br />

public XPathFunctionException(java.lang.Exception cause);<br />

public XPathFunctionException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Author<br />

Norman Walsh [mailto:Norman.Walsh@Sun.com], Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.1 $, $Date: 2003/12/08 04:40:46 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

java.lang.Throwable<br />

|<br />

java.lang.Exception<br />

|<br />

javax.xml.xpath.XPathException<br />

|<br />

javax.xml.xpath.XPathExpressionException<br />

|<br />

javax.xml.xpath.XPathFunctionException<br />

Members<br />

Constructor XPathFunctionException(Exception)<br />

public XPathFunctionException(java.lang.Exception cause);<br />

152


Community Draft<br />

Package javax.xml.xpath<br />

Community Draft<br />

Parameters<br />

cause<br />

The cause.<br />

Exceptions<br />

NullPointerException<br />

if cause is null.<br />

Constructs a new XPathFunctionException with the specified cause.<br />

If cause is null, then a NullPointerException is thrown.<br />

Constructor XPathFunctionException(String)<br />

public XPathFunctionException(java.lang.String message);<br />

Parameters<br />

message<br />

The detail message.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathFunctionException with the specified detail message.<br />

The cause is not initialized.<br />

If message is null, then a NullPointerException is thrown.<br />

Constructor XPathFunctionException(String, Exception)<br />

public XPathFunctionException(java.lang.String message,<br />

java.lang.Exception cause);<br />

Parameters<br />

message<br />

cause<br />

The detail message.<br />

The cause. A null value is permitted, and indicates that the cause is nonexistent or unknown.<br />

Exceptions<br />

NullPointerException<br />

If message is null.<br />

Constructs a new XPathFunctionException with the specified detail message and cause.<br />

If message is null, then a NullPointerException is thrown.<br />

153


Community Draft<br />

Community Draft<br />

Chapter 15. Package javax.xml.validation<br />

Provides classes <strong>for</strong> schem-language agnostic validation.<br />

Class AbstractSchemaImpl<br />

Synopsis<br />

Partial implementation of javax.xml.validation.Schema [ Class Schema].<br />

This class is intended to be used as the base class by the implementations of the validation <strong>API</strong>, to promote consistent<br />

behaviors among javax.xml.validation.Schema [ Class Schema] implementations.<br />

The only remaining method that has to be implemented by the derived class is javax.xml.validation.Schema.newVal<br />

idatorHandler [ Method newValidatorHandler()].<br />

}<br />

public AbstractSchemaImpl extends Schema {<br />

protected AbstractSchemaImpl();<br />

public Validator newValidator();<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: <strong>1.3</strong> $, $Date: 2003/12/06 00:21:37 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.Schema<br />

|<br />

javax.xml.validation.AbstractSchemaImpl<br />

Members<br />

Constructor AbstractSchemaImpl()<br />

protected AbstractSchemaImpl();<br />

A do-nothing constructor.<br />

Method newValidator()<br />

public Validator newValidator();<br />

See Also<br />

javax.xml.validation.Schema.newValidator [Method newValidator()]<br />

154


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Creates a default implementation of javax.xml.validation.Validator [ Class Validator] by using javax.xml.valida<br />

tion.Schema.newValidatorHandler [ Method newValidatorHandler()].<br />

Class Schema<br />

Synopsis<br />

Immutable in-memory representation of grammar.<br />

This object represents a set of constraints that can be checked/ en<strong>for</strong>ced against an <strong>XML</strong> document.<br />

A javax.xml.validation.Schema [ Class Schema] object is thread safe and applications are encouraged to share it across<br />

many parsers in many threads.<br />

A javax.xml.validation.Schema [ Class Schema] object is immutable in the sense that it shouldn't change the set of<br />

constraints once it is created. In other words, if an application validates the same document twice against the same<br />

javax.xml.validation.Schema [ Class Schema], it must always produce the same result.<br />

A javax.xml.validation.Schema [ Class Schema] object is usually created from javax.xml.validation.SchemaFactory [<br />

Class SchemaFactory].<br />

Two kinds of validators can be created from a javax.xml.validation.Schema [ Class Schema] object. One is<br />

javax.xml.validation.Validator [ Class Validator], which provides highly-level validation operations that cover typical<br />

use cases. The other is javax.xml.validation.ValidatorHandler [ Class ValidatorHandler], which works on top of SAX<br />

<strong>for</strong> better modularity.<br />

This specification does not refine the java.lang.Object.equals method. In other words, if you parse the same schema<br />

twice, you may still get !schemaA.equals(schemaB).<br />

}<br />

public Schema {<br />

protected Schema();<br />

public Validator abstract newValidator();<br />

public ValidatorHandler abstract newValidatorHandler();<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.4 $, $Date: 2003/12/06 00:21:36 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

<strong>XML</strong> Schema Part 1: Structures [http://www.w3.org/TR/xmlschema-1/], Extensible Markup Lan<br />

guage (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11/], Extensible Markup Language (<strong>XML</strong>) 1.0<br />

(Second Edition) [http://www.w3.org/TR/REC-xml]<br />

java.lang.Object<br />

|<br />

javax.xml.validation.Schema<br />

155


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Members<br />

Constructor Schema()<br />

protected Schema();<br />

Constructor <strong>for</strong> the derived class.<br />

The constructor does nothing.<br />

Method newValidator()<br />

public Validator abstract newValidator();<br />

Creates a new javax.xml.validation.Validator [ Class Validator] <strong>for</strong> this javax.xml.validation.Schema [ Class Schema].<br />

A validator en<strong>for</strong>ces/checks the set of constraints this object represents.<br />

Method newValidatorHandler()<br />

public ValidatorHandler abstract newValidatorHandler();<br />

Creates a new javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] <strong>for</strong> this javax.xml.validation.Schema<br />

[ Class Schema].<br />

Class SchemaFactory<br />

Factory that creates javax.xml.validation.Schema [ Class Schema] objects&#x2E; Entry-point to the validation <strong>API</strong>.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] is a schema compiler. It reads external representations<br />

of schemas and prepare them <strong>for</strong> validation.<br />

The javax.xml.validation.SchemaFactory [ Class SchemaFactory] class is not thread-safe. In other words, it is applic<br />

ations' responsibility to ensure that at most one thread is using a javax.xml.validation.SchemaFactory [ Class Schema<br />

Factory] object at any given moment. Implementations are encouraged to mark methods as<br />

synchronized<br />

to protect itself from broken clients.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] is not re-entrant. While one of the newSchema method<br />

is being invoked, applications may not attempt to recursively invoke the newSchema method even from the same<br />

thread.<br />

Schema Language<br />

This spec uses a namespace URI to designate a schema language. The following table shows the values defined by<br />

this specification.<br />

To be compliant with the spec, the implementation is only required to support W3C <strong>XML</strong> Schema 1.0, however if it<br />

chooses to support other schema languages listed here, it must con<strong>for</strong>m to the relevant behaviors described in this spec.<br />

156


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Schema languages not listed here are expected to introduce their own URIs to represent themselves. The<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] class is capable of locating other implementations <strong>for</strong><br />

other schema languages at run-time.<br />

Please note that this draft does not support DTD <strong>for</strong> the following reasons, and we are interested in how people feel<br />

on this issue. The expert group felt that the DTD support would inevitably introduce significant complexity, and that<br />

the benefit doesn't worth the cost.<br />

value<br />

http://www.w3.org/2001/<strong>XML</strong>Schema<br />

http://relaxng.org/ns/structure/1.0<br />

language<br />

W3C <strong>XML</strong> Schema 1.0<br />

[http://www.w3.org/TR/xmlschema-1]<br />

RELAX NG 1.0 [http://www.relaxng.org/]<br />

Synopsis<br />

public SchemaFactory {<br />

protected SchemaFactory();<br />

static SchemaFactory newInstance(java.lang.String schemaLanguage);<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

public ErrorHandler abstract getErrorHandler();<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

public LSResourceResolver abstract getResourceResolver();<br />

public Schema newSchema(javax.xml.trans<strong>for</strong>m.Source schema)<br />

throws org.xml.sax.SAXException;<br />

public Schema newSchema(java.io.File schema)<br />

throws org.xml.sax.SAXException;<br />

public Schema newSchema(java.net.URL schema)<br />

throws org.xml.sax.SAXException;<br />

public Schema abstract newSchema(javax.xml.trans<strong>for</strong>m.Source[] schemas)<br />

throws org.xml.sax.SAXException;<br />

157


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

public Schema abstract newSchema()<br />

throws org.xml.sax.SAXException;<br />

}<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.13 $, $Date: 2003/12/06 00:21:37 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.SchemaFactory<br />

Members<br />

Constructor SchemaFactory()<br />

protected SchemaFactory();<br />

Constructor <strong>for</strong> derived classes.<br />

The constructor does nothing.<br />

Derived classes should create javax.xml.validation.SchemaFactory [ Class SchemaFactory] objects that have null<br />

org.xml.sax.ErrorHandler and null org.w3c.dom.ls.LSResourceResolver.<br />

Method getErrorHandler()<br />

public ErrorHandler abstract getErrorHandler();<br />

See Also<br />

javax.xml.validation.SchemaFactory.setErrorHandler [Method setErrorHandler(org.xml.sax.Er<br />

rorHandler)]<br />

Gets the current org.xml.sax.ErrorHandler set to this javax.xml.validation.SchemaFactory [ Class SchemaFactory].<br />

Method getFeature(String)<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The feature name, which is a non-null fully-qualified URI.<br />

The current value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

If the feature value can't be assigned or retrieved.<br />

158


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

When the javax.xml.validation.SchemaFactory [ Class SchemaFactory] recognizes the<br />

feature name but cannot determine its value at this time.<br />

if the name parameter is null.<br />

See Also<br />

javax.xml.validation.SchemaFactory.setFeature [Method setFeature(java.lang.String, boolean)]<br />

Look up the value of a feature flag.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.SchemaFactory [ Class Schema<br />

Factory] to recognize a feature name but temporarily be unable to return its value.<br />

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.<br />

Method getProperty(String)<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The property name, which is a non-null fully-qualified URI.<br />

The current value of the property.<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the property value can't be assigned or retrieved.<br />

When the <strong>XML</strong>Reader recognizes the property name but cannot determine its value at<br />

this time.<br />

if the name parameter is null.<br />

See Also javax.xml.validation.SchemaFactory.setProperty [Method setProperty(java.lang.String,<br />

java.lang.Object)]<br />

Look up the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.SchemaFactory [ Class Schem<br />

aFactory] to recognize a property name but temporarily be unable to return its value.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory]s are not required to recognize any specific property<br />

names.<br />

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.<br />

Method getResourceResolver()<br />

public LSResourceResolver abstract getResourceResolver();<br />

See Also<br />

javax.xml.validation.SchemaFactory.setErrorHandler [Method setErrorHandler(org.xml.sax.Er<br />

rorHandler)]<br />

159


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Gets the current org.w3c.dom.ls.LSResourceResolver set to this javax.xml.validation.SchemaFactory [ Class Schema<br />

Factory].<br />

Method newInstance(String)<br />

static SchemaFactory newInstance(java.lang.String schemaLanguage);<br />

Parameters<br />

schemaLanguage<br />

returns<br />

Specifies the schema language which the returned SchemaFactory will understand. See<br />

the list of available schema languages [#schemaLanguage] <strong>for</strong> the possible values.<br />

New instance of a SchemaFactory<br />

Exceptions<br />

IllegalArgumentException<br />

NullPointerException<br />

If no implementation of the schema language is available.<br />

If the<br />

schemLanguage<br />

parameter is null.<br />

See Also<br />

javax.xml.validation.SchemaFactoryFinder [Class SchemaFactoryFinder]<br />

Looks <strong>for</strong> an implementation of the javax.xml.validation.SchemaFactory [ Class SchemaFactory] class <strong>for</strong> a given<br />

schema language and returns it.<br />

This method is just a convenience method of:<br />

new javax.xml.validation.SchemaFactoryFinder [<br />

Class SchemaFactoryFinder](classLoader).newFactory(schemaLanguage);<br />

where<br />

classLoader<br />

is the context class loader (in JDK1.2 or later) or the system class loader (in JDK versions earlier than 1.2)<br />

Method newSchema()<br />

public Schema abstract newSchema()<br />

throws org.xml.sax.SAXException;<br />

160


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Exceptions<br />

UnsupportedOperationEx<br />

ception<br />

SAXException<br />

If this operation is not supported by the callee.<br />

If this operation is supported but failed <strong>for</strong> some reason.<br />

Creates a special javax.xml.validation.Schema [ Class Schema] object.<br />

The exact semantics of the returned javax.xml.validation.Schema [ Class Schema] object depends on the schema language<br />

that this javax.xml.validation.SchemaFactory [ Class SchemaFactory] is created <strong>for</strong>.<br />

Also, implementations are allowed to use implementation-specific property/feature to alter the semantics of this<br />

method.<br />

W3C <strong>XML</strong> Schema 1.0<br />

RELAX NG<br />

For <strong>XML</strong> Schema, this method creates a javax.xml.validation.Schema [ Class Schema] object that per<strong>for</strong>ms validation<br />

by using location hints specified in documents.<br />

The returned javax.xml.validation.Schema [ Class Schema] object assumes that if documents refer to the same URL<br />

in the schema location hints, they will always resolve to the same schema document. This asusmption allows imple<br />

mentations to reuse parsed results of schema documents so that multiple validations against the same schema will run<br />

faster.<br />

Note that the use of schema location hints introduces a vulnerability to denial-of-service attacks.<br />

RELAX NG does not support this operation.<br />

Method newSchema(File)<br />

public Schema newSchema(java.io.File schema)<br />

throws org.xml.sax.SAXException;<br />

Parameters<br />

schema<br />

returns<br />

File that represents a schema.<br />

New Schema from parsing schema.<br />

Exceptions<br />

SAXException<br />

NullPointerException<br />

If a SAX error occurs during parsing.<br />

if<br />

schema<br />

is null.<br />

Parses the specified File as a schema and returns it as a Schema.<br />

161


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

This is a convenience method <strong>for</strong> javax.xml.validation.SchemaFactory.newSchema [ Method newSchema(javax.xml.trans<br />

<strong>for</strong>m.Source)].<br />

Method newSchema(Source)<br />

public Schema newSchema(javax.xml.trans<strong>for</strong>m.Source schema)<br />

throws org.xml.sax.SAXException;<br />

Parameters<br />

schema<br />

returns<br />

Source that represents a schema.<br />

New Schema from parsing schema.<br />

Exceptions<br />

SAXException<br />

NullPointerException<br />

If a SAX error occurs during parsing.<br />

if<br />

schema<br />

is null.<br />

Parses the specified source as a schema and returns it as a schema.<br />

This is a convenience method <strong>for</strong> javax.xml.validation.SchemaFactory.newSchema [ Method newSchema(javax.xml.trans<br />

<strong>for</strong>m.Source[])].<br />

Method newSchema(Source[])<br />

public Schema abstract newSchema(javax.xml.trans<strong>for</strong>m.Source[] schemas)<br />

throws org.xml.sax.SAXException;<br />

Parameters<br />

schemas<br />

returns<br />

inputs to be parsed. javax.xml.validation.SchemaFactory [ Class SchemaFactory] is required to re<br />

cognize javax.xml.trans<strong>for</strong>m.sax.SAXSource, javax.xml.trans<strong>for</strong>m.stream.StreamSource, and<br />

javax.xml.trans<strong>for</strong>m.dom.DOMSource.<br />

Always return a non-null valid javax.xml.validation.Schema [ Class Schema] object. Note that when<br />

an error has been reported, there is no guarantee that the returned javax.xml.validation.Schema [<br />

Class Schema] object is meaningful.<br />

Exceptions<br />

SAXException<br />

NullPointerException<br />

IllegalArgumentException<br />

If an error is found during processing the specified inputs. When an org.xml.sax.Er<br />

rorHandler is set, errors are reported to there first. See javax.xml.validation.SchemaFact<br />

ory.setErrorHandler [ Method setErrorHandler(org.xml.sax.ErrorHandler)].<br />

If the schemas parameter itself is null or any item in the array is null.<br />

If any item in the array is not recognized by this method.<br />

162


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Parses the specified source(s) as a schema and returns it as a schema.<br />

The callee will read all the javax.xml.trans<strong>for</strong>m.Sources and combine them into a single schema. The exact semantics<br />

of the combination depends on the schema language that this javax.xml.validation.SchemaFactory [ Class SchemaFactory]<br />

object is created <strong>for</strong>.<br />

When an org.xml.sax.ErrorHandler is set, the callee will report all the errors found in sources to the handler. If the<br />

handler throws an exception, it will abort the schema compilation and the same exception will be thrown from this<br />

method. Also, after an error is reported to a handler, the callee is allowed to abort the further processing by throwing<br />

it. If an error handler is not set, the callee will throw the first error it finds in the sources.<br />

W3C <strong>XML</strong> Schema 1.0<br />

RELAX NG<br />

For <strong>XML</strong> Schema, all definitions in all the sources are pulled together and assembled into one schema, as specified in<br />

the section 4.2 of the <strong>XML</strong> Schema spec.<br />

If the parsed set of schemas includes error(s) as specified in the section 5.1 of the <strong>XML</strong> Schema spec, then the error<br />

must be reported to the org.xml.sax.ErrorHandler.<br />

For RELAX NG, when multiple sources s1,s2,...,sn are specified, it will be treated as if the following single input was<br />

given.<br />

<br />

<br />

<br />

<br />

<br />

...<br />

<br />

<br />

<br />

<br />

Method newSchema(URL)<br />

public Schema newSchema(java.net.URL schema)<br />

throws org.xml.sax.SAXException;<br />

Parameters<br />

schema<br />

returns<br />

URL that represents a schema.<br />

New Schema from parsing schema.<br />

Exceptions<br />

SAXException<br />

NullPointerException<br />

If a SAX error occurs during parsing.<br />

if<br />

163


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

schema<br />

is null.<br />

Parses the specified URL as a schema and returns it as a Schema.<br />

This is a convenience method <strong>for</strong> javax.xml.validation.SchemaFactory.newSchema [ Method newSchema(javax.xml.trans<br />

<strong>for</strong>m.Source)].<br />

Method setErrorHandler(ErrorHandler)<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

Parameters<br />

errorHandler<br />

A new error handler to be set. This parameter can be null.<br />

Sets the org.xml.sax.ErrorHandler to receive errors encountered during the newSchema method invocation.<br />

Error handler can be used to customize the error handling process during schema parsing. When an org.xml.sax.Er<br />

rorHandler is set, errors found during the parsing of schemas will be first sent to the org.xml.sax.ErrorHandler.<br />

The error handler can abort the parsing of a schema immediately by throwing org.xml.sax.SAXException from the<br />

handler. Or <strong>for</strong> example it can print an error to the screen and try to continue the processing by returning normally<br />

from the org.xml.sax.ErrorHandler<br />

If any java.lang.Throwable (or instances of its derived classes) is thrown from an org.xml.sax.ErrorHandler, the caller<br />

of the newSchema method will be thrown the same java.lang.Throwable object.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] is not allowed to throw org.xml.sax.SAXException without<br />

first reporting it to org.xml.sax.ErrorHandler.<br />

Applications can call this method even during a javax.xml.validation.Schema [ Class Schema] is being parsed.<br />

When the org.xml.sax.ErrorHandler is null, the implementation will behave as if the following org.xml.sax.ErrorHandler<br />

is set:<br />

class DraconianErrorHandler implements<br />

org.xml.sax.ErrorHandler {<br />

public void fatalError(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

public void error(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

public void warning(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

164


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

}<br />

}<br />

// noop<br />

When a new javax.xml.validation.SchemaFactory [ Class SchemaFactory] object is created, initially this field is set<br />

to null. This field will NOT be inherited to javax.xml.validation.Schema [ Class Schema]s, javax.xml.validation.Val<br />

idator [ Class Validator]s, or javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]s that are created from<br />

this javax.xml.validation.SchemaFactory [ Class SchemaFactory].<br />

Method setFeature(String, boolean)<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

value<br />

The feature name, which is a non-null fully-qualified URI.<br />

The requested value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the feature value can't be assigned or retrieved.<br />

When the javax.xml.validation.SchemaFactory [ Class SchemaFactory] recognizes the<br />

feature name but cannot set the requested value.<br />

if the name parameter is null.<br />

See Also<br />

javax.xml.validation.SchemaFactory.getFeature [Method getFeature(java.lang.String)]<br />

Set the value of a feature flag.<br />

Feature can be used to control the way a javax.xml.validation.SchemaFactory [ Class SchemaFactory] parses schemas,<br />

although javax.xml.validation.SchemaFactory [ Class SchemaFactory]s are not required to recognize any specific<br />

feature names.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.SchemaFactory [ Class Schema<br />

Factory] to expose a feature value but to be unable to change the current value.<br />

Method setProperty(String, Object)<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

object<br />

The property name, which is a non-null fully-qualified URI.<br />

The requested value <strong>for</strong> the property.<br />

165


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

If the property value can't be assigned or retrieved.<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

When the javax.xml.validation.SchemaFactory [ Class SchemaFactory] recognizes the<br />

property name but cannot set the requested value.<br />

if the name parameter is null.<br />

Set the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.SchemaFactory [ Class Schem<br />

aFactory] to recognize a property name but to be unable to change the current value.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory]s are not required to recognize setting any specific property<br />

names.<br />

Method setResourceResolver(LSResourceResolver)<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

Parameters<br />

resourceResolver<br />

A new resource resolver to be set. This parameter can be null.<br />

Sets the org.w3c.dom.ls.LSResourceResolver to customize resource resolution when parsing schemas.<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] uses a org.w3c.dom.ls.LSResourceResolver when it needs<br />

to locate external resources while parsing schemas, although exactly what constitutes "locating external resources" is<br />

up to each schema language. For example, <strong>for</strong> W3C <strong>XML</strong> Schema, this includes files<br />

<br />

d or<br />

<br />

ed, and DTD referenced from schema files, etc.<br />

Applications can call this method even during a javax.xml.validation.Schema [ Class Schema] is being parsed.<br />

When the org.w3c.dom.ls.LSResourceResolver is null, the implementation will behave as if the following<br />

org.w3c.dom.ls.LSResourceResolver is set:<br />

class DumbDOMResourceResolver implements<br />

org.w3c.dom.ls.LSResourceResolver {<br />

public<br />

org.w3c.dom.ls.LSInput resolveResource(<br />

String publicId, String systemId, String baseURI) {<br />

166


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

}<br />

}<br />

return null; // always return null<br />

If a org.w3c.dom.ls.LSResourceResolver throws a java.lang.RuntimeException (or instances of its derived classes),<br />

then the javax.xml.validation.SchemaFactory [ Class SchemaFactory] will abort the parsing and the caller of the<br />

newSchema method will receive the same java.lang.RuntimeException. When a new javax.xml.validation.Schema<br />

Factory [ Class SchemaFactory] object is created, initially this field is set to null. This field will NOT be inherited to<br />

javax.xml.validation.Schema [ Class Schema]s, javax.xml.validation.Validator [ Class Validator]s, or javax.xml.valid<br />

ation.ValidatorHandler [ Class ValidatorHandler]s that are created from this javax.xml.validation.SchemaFactory [<br />

Class SchemaFactory].<br />

Class SchemaFactoryFinder<br />

Implementation of javax.xml.validation.SchemaFactoryLoader [ Class SchemaFactoryLoader] that locates<br />

javax.xml.validation.SchemaFactory [ Class SchemaFactory] dynamically.<br />

Applications should first consider using the javax.xml.validation.SchemaFactory.newInstance [ Method newIn<br />

stance(java.lang.String)] method be<strong>for</strong>e using this class.<br />

This class implements the actual logic of the abovementioned method, and applications may use this class directly <strong>for</strong><br />

more flexible processing (such as to specify the java.lang.ClassLoader, etc.)<br />

Resolution Process<br />

To find a javax.xml.validation.SchemaFactory [ Class SchemaFactory] object <strong>for</strong> a given schema language, this loader<br />

looks the following places in this order:<br />

1. If the system property "javax.xml.validation.SchemaFactory:schemaLanguage" is present<br />

(where schemaLanguage is the name of the schema language that the loader is looking <strong>for</strong>), then its value is read<br />

as ':'-separated list of class names. The loader will try to create a new instance of these classes in the order of the<br />

list, and it returns the first one that it succeeds.<br />

2. $java.home/lib/jaxp.properties is read and the value associated with the key being the system<br />

property above is looked <strong>for</strong>. If present, the value is processed just like above.<br />

3. If the system property "javax.xml.validation.SchemaFactoryLoader" is present, then the value<br />

is read as a ':'-separated list of class names. For each class in this list, if the loader can create a new instance of<br />

the class, then its javax.xml.validation.SchemaFactoryLoader.newFactory [ Method newFactory(java.lang.String)]<br />

method is used to try to locate a javax.xml.validation.SchemaFactory [ Class SchemaFactory] object.<br />

4. If the above step fails, then $java.home/lib/jaxp.properties is read and the value associated with<br />

the key being the system property above is read. If present, the value is processed just like above.<br />

5. META-INF/services/javax.xml.validation.SchemaFactoryLoader in the jar files are searched,<br />

and if files are present, they are read in the order they are found, and class names are extracted from each file.<br />

The <strong>for</strong>mat of this file will be explained later. Instance of those classes are created one by one and their<br />

javax.xml.validation.SchemaFactoryLoader.newFactory [ Method newFactory(java.lang.String)] method is used<br />

to try to locate a javax.xml.validation.SchemaFactory [ Class SchemaFactory] object.<br />

6. Plat<strong>for</strong>m default SchemaFactoryLoader instance is consulted.<br />

167


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

If everything fails, the javax.xml.validation.SchemaFactoryFinder.newFactory [ Method newFactory(java.lang.String)]<br />

method returns null.<br />

Tip <strong>for</strong> Trouble-shooting<br />

Setting the jaxp.debug system property will cause javax.xml.validation.SchemaFactoryFinder [ Class SchemaFact<br />

oryFinder] to print a lot of debug messages to<br />

System.err<br />

about what it is doing and where it is looking at.<br />

If you have problems loading javax.xml.validation.SchemaFactory [ Class SchemaFactory]s, try:<br />

java -Djaxp.debug=1 YourProgram ....<br />

F i l e F o r m a t o f<br />

META-INF/services/javax.xml.validation.SchemaFactoryLoader<br />

Example<br />

File is assumed to be encoded in UTF-8. Lines starting from '#' or lines that only consists of whitespaces will be ignored.<br />

Other lines will be trimed and considered as a class name.<br />

# my service property file<br />

# this class will be consulted first.<br />

org.acme.foo.MySchemaFactoryLoaderImpl<br />

# then if the above loader can't find it,<br />

# this will be used second<br />

org.acme.foo.AnotherSchemaFactoryLoaderImpl<br />

# EOF<br />

Synopsis<br />

public SchemaFactoryFinder extends SchemaFactoryLoader {<br />

public SchemaFactoryFinder(java.lang.ClassLoader loader);<br />

public SchemaFactory newFactory(java.lang.String schemaLanguage);<br />

}<br />

168


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Author<br />

Kohsuke Kawaguchi [Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/11 21:39:09 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.SchemaFactoryLoader<br />

|<br />

javax.xml.validation.SchemaFactoryFinder<br />

Members<br />

Constructor SchemaFactoryFinder(ClassLoader)<br />

public SchemaFactoryFinder(java.lang.ClassLoader loader);<br />

Parameters<br />

loader<br />

to be used to load resource, javax.xml.validation.SchemaFactory [ Class SchemaFactory], and<br />

javax.xml.validation.SchemaFactoryLoader [ Class SchemaFactoryLoader] implementations during<br />

the resolution process. If this parameter is null, the default system class loader will be used.<br />

Constructor that specifies ClassLoader to use to find SchemaFactory.<br />

Method newFactory(String)<br />

public SchemaFactory newFactory(java.lang.String schemaLanguage);<br />

Parameters<br />

schemaLanguage<br />

returns<br />

See the list of available schema languages [../SchemaFactory.html#schemaLanguage]<br />

null if the callee fails to create one.<br />

Exceptions<br />

NullPointerException<br />

If the<br />

schemaLanguage<br />

parameter is null.<br />

Creates a new javax.xml.validation.SchemaFactory [ Class SchemaFactory] object <strong>for</strong> the specified schema language.<br />

Class SchemaFactoryLoader<br />

Factory that creates javax.xml.validation.SchemaFactory [ Class SchemaFactory].<br />

169


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Synopsis<br />

This class is intended to be used by the implementations of the validation <strong>API</strong>, not by users.<br />

public SchemaFactoryLoader {<br />

protected SchemaFactoryLoader();<br />

public SchemaFactory abstract newFactory(java.lang.String schemaLanguage);<br />

}<br />

Author<br />

Kohsuke Kawaguchi [Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.4 $, $Date: 2003/12/06 00:21:38 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.SchemaFactoryLoader<br />

Members<br />

Constructor SchemaFactoryLoader()<br />

protected SchemaFactoryLoader();<br />

A do-nothing constructor.<br />

Method newFactory(String)<br />

public SchemaFactory abstract newFactory(java.lang.String schemaLanguage);<br />

Parameters<br />

schemaLanguage<br />

returns<br />

See the list of available schema languages [../SchemaFactory.html#schemaLanguage].<br />

null if the callee fails to create one.<br />

Exceptions<br />

NullPointerException<br />

If the<br />

schemaLanguage<br />

parameter is null.<br />

Creates a new javax.xml.validation.SchemaFactory [ Class SchemaFactory] object <strong>for</strong> the specified schema language.<br />

170


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Class TypeInfoProvider<br />

Synopsis<br />

This class provides access to the type in<strong>for</strong>mation determined by javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler].<br />

Some schema languages, such as W3C <strong>XML</strong> Schema, encourages a validator to report the "type" it assigns to each<br />

attribute/element. Those applications who wish to access this type in<strong>for</strong>mation can invoke methods defined on this<br />

"interface" to access such type in<strong>for</strong>mation.<br />

Implementation of this "interface" can be obtained through the javax.xml.validation.ValidatorHandler.getTypeInfoPro<br />

vider [ Method getTypeInfoProvider()] method.<br />

}<br />

public TypeInfoProvider {<br />

protected TypeInfoProvider();<br />

public TypeInfo abstract getElementTypeInfo();<br />

public TypeInfo abstract getAttributeTypeInfo(int index);<br />

public boolean abstract isIdAttribute(int index);<br />

public boolean abstract isSpecified(int index);<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.10 $, $Date: 2003/12/06 00:21:36 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

org.w3c.dom.TypeInfo<br />

java.lang.Object<br />

|<br />

javax.xml.validation.TypeInfoProvider<br />

Members<br />

Constructor TypeInfoProvider()<br />

protected TypeInfoProvider();<br />

Constructor <strong>for</strong> the derived class.<br />

The constructor does nothing.<br />

171


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Method getAttributeTypeInfo(int)<br />

public TypeInfo abstract getAttributeTypeInfo(int index);<br />

Parameters<br />

index<br />

The index of the attribute. The same index <strong>for</strong> the org.xml.sax.Attributes object passed to the<br />

startElement<br />

callback.<br />

returns<br />

An immutable org.w3c.dom.TypeInfo object that represents the type of the specified attribute. Note<br />

that the caller can keep references to the obtained org.w3c.dom.TypeInfo longer than the callback<br />

scope. Otherwise, this method returns null if the validator is unable to determine the type.<br />

Exceptions<br />

IndexOutOfBoundsExcep<br />

tion<br />

IllegalStateException<br />

If the index is invalid.<br />

If this method is called from other org.xml.sax.ContentHandler methods.<br />

Returns the immutable org.w3c.dom.TypeInfo object <strong>for</strong> the specified attribute of the current element.<br />

The method may only be called by the startElement event of the org.xml.sax.ContentHandler that the application sets<br />

to the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler].<br />

Method getElementTypeInfo()<br />

public TypeInfo abstract getElementTypeInfo();<br />

Exceptions<br />

IllegalStateException<br />

If this method is called from other org.xml.sax.ContentHandler methods.<br />

Returns the immutable org.w3c.dom.TypeInfo object <strong>for</strong> the current element.<br />

The method may only be called by the startElement event of the org.xml.sax.ContentHandler that the application sets<br />

to the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler].<br />

Method isIdAttribute(int)<br />

public boolean abstract isIdAttribute(int index);<br />

Parameters<br />

index<br />

The index of the attribute. The same index <strong>for</strong> the org.xml.sax.Attributes object passed to the<br />

startElement<br />

callback.<br />

172


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

returns<br />

Exceptions<br />

true if the type of the specified attribute is ID.<br />

IndexOutOfBoundsExcep<br />

tion<br />

IllegalStateException<br />

If the index is invalid.<br />

If this method is called from other org.xml.sax.ContentHandler methods.<br />

Returns<br />

true<br />

if the specified attribute is determined to be ID.<br />

A javax.xml.parsers.DocumentBuilder uses this in<strong>for</strong>mation to properly implement org.w3c.dom.Attr.isId.<br />

The method may only be called by the startElement event of the org.xml.sax.ContentHandler that the application sets<br />

to the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler].<br />

Method isSpecified(int)<br />

public boolean abstract isSpecified(int index);<br />

Parameters<br />

index<br />

The index of the attribute. The same index <strong>for</strong> the org.xml.sax.Attributes object passed to the<br />

startElement<br />

callback.<br />

returns<br />

true<br />

if the attribute was present be<strong>for</strong>e the validator processes input.<br />

false<br />

if the attribute was added by the validator.<br />

Exceptions<br />

IndexOutOfBoundsExcep<br />

tion<br />

IllegalStateException<br />

If the index is invalid.<br />

If this method is called from other org.xml.sax.ContentHandler methods.<br />

Returns<br />

173


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

false<br />

if the attribute was added by the validator.<br />

This method provides in<strong>for</strong>mation necessary <strong>for</strong> a javax.xml.parsers.DocumentBuilder to determine what the DOM<br />

tree should return from the org.w3c.dom.Attr.getSpecified method.<br />

The method may only be called by the startElement event of the org.xml.sax.ContentHandler that the application sets<br />

to the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler].<br />

A general guideline <strong>for</strong> validators is to return true if the attribute was originally present in the pipeline, and false if it<br />

was added by the validator.<br />

Class Validator<br />

A processor that checks an <strong>XML</strong> document against javax.xml.validation.Schema [ Class Schema].<br />

A validator is a thread-unsafe and non-reentrant object. In other words, it is applications' responsibility to make sure<br />

that one javax.xml.validation.Validator [ Class Validator] object is not used from more than one thread at any given<br />

time, and while the<br />

validate<br />

method is invoked, applications may not recursively call the<br />

validate<br />

method.<br />

Synopsis<br />

public Validator {<br />

protected Validator();<br />

public void validate(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void abstract validate(javax.xml.trans<strong>for</strong>m.Source source,<br />

javax.xml.trans<strong>for</strong>m.Result result)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

public ErrorHandler abstract getErrorHandler();<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

public LSResourceResolver abstract getResourceResolver();<br />

174


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

}<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.16 $, $Date: 2003/12/06 00:21:37 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.Validator<br />

Members<br />

Constructor Validator()<br />

protected Validator();<br />

Constructor <strong>for</strong> derived classes.<br />

The constructor does nothing.<br />

Derived classes should create javax.xml.validation.Validator [ Class Validator] objects that have<br />

null<br />

org.xml.sax.ErrorHandler and<br />

null<br />

org.w3c.dom.ls.LSResourceResolver.<br />

Method getErrorHandler()<br />

public ErrorHandler abstract getErrorHandler();<br />

175


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

See Also<br />

javax.xml.validation.Validator.setErrorHandler [Method setErrorHandler(org.xml.sax.ErrorHandler)]<br />

Gets the current org.xml.sax.ErrorHandler set to this javax.xml.validation.Validator [ Class Validator].<br />

Method getFeature(String)<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The feature name, which is a non-null fully-qualified URI.<br />

The current value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the feature value can't be assigned or retrieved.<br />

When the javax.xml.validation.Validator [ Class Validator] recognizes the feature name<br />

but cannot determine its value at this time.<br />

When the name parameter is null.<br />

See Also<br />

javax.xml.validation.Validator.setFeature [Method setFeature(java.lang.String, boolean)]<br />

Look up the value of a feature flag.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.Validator [ Class Validator] to<br />

recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in<br />

specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.<br />

Method getProperty(String)<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The property name, which is a non-null fully-qualified URI.<br />

The current value of the property.<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the property value can't be assigned or retrieved.<br />

When the <strong>XML</strong>Reader recognizes the property name but cannot determine its value at<br />

this time.<br />

When the name parameter is null.<br />

176


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

See Also<br />

javax.xml.validation.Validator.setProperty [Method setProperty(java.lang.String, java.lang.Object)]<br />

Look up the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.Validator [ Class Validator] to<br />

recognize a property name but temporarily be unable to return its value. Some property values may be available only<br />

in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

javax.xml.validation.Validator [ Class Validator]s are not required to recognize any specific property names.<br />

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.<br />

Method getResourceResolver()<br />

public LSResourceResolver abstract getResourceResolver();<br />

See Also<br />

javax.xml.validation.Validator.setErrorHandler [Method setErrorHandler(org.xml.sax.ErrorHandler)]<br />

Gets the current org.w3c.dom.ls.LSResourceResolver set to this javax.xml.validation.Validator [ Class Validator].<br />

Method setErrorHandler(ErrorHandler)<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

Parameters<br />

errorHandler<br />

A new error handler to be set. This parameter can be null.<br />

Sets the org.xml.sax.ErrorHandler to receive errors encountered during the validate method invocation.<br />

Error handler can be used to customize the error handling process during a validation. When an org.xml.sax.ErrorHandler<br />

is set, errors found during the validation will be first sent to the org.xml.sax.ErrorHandler.<br />

The error handler can abort further validation immediately by throwing org.xml.sax.SAXException from the handler.<br />

Or <strong>for</strong> example it can print an error to the screen and try to continue the validation by returning normally from the<br />

org.xml.sax.ErrorHandler<br />

If any java.lang.Throwable is thrown from an org.xml.sax.ErrorHandler, the caller of the validate method will be<br />

thrown the same java.lang.Throwable object.<br />

javax.xml.validation.Validator [ Class Validator] is not allowed to throw org.xml.sax.SAXException without first re<br />

porting it to org.xml.sax.ErrorHandler.<br />

When the org.xml.sax.ErrorHandler is null, the implementation will behave as if the following org.xml.sax.ErrorHandler<br />

is set:<br />

class DraconianErrorHandler implements<br />

org.xml.sax.ErrorHandler {<br />

public void fatalError(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

177


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

}<br />

public void error(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

public void warning(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

// noop<br />

}<br />

When a new javax.xml.validation.Validator [ Class Validator] object is created, initially this field is set to null.<br />

Method setFeature(String, boolean)<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

value<br />

The feature name, which is a non-null fully-qualified URI.<br />

The requested value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the feature value can't be assigned or retrieved.<br />

When the javax.xml.validation.Validator [ Class Validator] recognizes the feature name<br />

but cannot set the requested value.<br />

When the name parameter is null.<br />

See Also<br />

javax.xml.validation.Validator.getFeature [Method getFeature(java.lang.String)]<br />

Set the value of a feature flag.<br />

Feature can be used to control the way a javax.xml.validation.Validator [ Class Validator] parses schemas, although<br />

javax.xml.validation.Validator [ Class Validator]s are not required to recognize any specific property names.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.Validator [ Class Validator] to<br />

expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable<br />

only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

Method setProperty(String, Object)<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

178


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Parameters<br />

name<br />

object<br />

The property name, which is a non-null fully-qualified URI.<br />

The requested value <strong>for</strong> the property.<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the property value can't be assigned or retrieved.<br />

When the javax.xml.validation.Validator [ Class Validator] recognizes the property name<br />

but cannot set the requested value.<br />

When the name parameter is null.<br />

Set the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.Validator [ Class Validator] to<br />

recognize a property name but to be unable to change the current value. Some property values may be immutable or<br />

mutable only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

javax.xml.validation.Validator [ Class Validator]s are not required to recognize setting any specific property names.<br />

Method setResourceResolver(LSResourceResolver)<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

Parameters<br />

resourceResolver<br />

A new resource resolver to be set. This parameter can be null.<br />

Sets the org.w3c.dom.ls.LSResourceResolver to customize resource resolution while in a validation episode.<br />

javax.xml.validation.Validator [ Class Validator] uses a org.w3c.dom.ls.LSResourceResolver when it needs to locate<br />

external resources while a validation, although exactly what constitutes "locating external resources" is up to each<br />

schema language.<br />

When the org.w3c.dom.ls.LSResourceResolver is null, the implementation will behave as if the following<br />

org.w3c.dom.ls.LSResourceResolver is set:<br />

class DumbLSResourceResolver implements<br />

org.w3c.dom.ls.LSResourceResolver {<br />

public<br />

org.w3c.dom.ls.LSInput resolveResource(<br />

String publicId, String systemId, String baseURI) {<br />

}<br />

}<br />

return null; // always return null<br />

179


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

If a org.w3c.dom.ls.LSResourceResolver throws a java.lang.RuntimeException (or instances of its derived classes),<br />

then the javax.xml.validation.Validator [ Class Validator] will abort the parsing and the caller of the validate<br />

method will receive the same java.lang.RuntimeException. When a new javax.xml.validation.Validator [ Class Valid<br />

ator] object is created, initially this field is set to null.<br />

Method validate(Source)<br />

public void validate(javax.xml.trans<strong>for</strong>m.Source source)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

See Also<br />

javax.xml.validation.Validator.setErrorHandler [Method setErrorHandler(org.xml.sax.ErrorHandler)]<br />

Validates the specified input.<br />

This is just a convenience method of:<br />

validate(source,null);<br />

Method validate(Source, Result)<br />

public void abstract validate(javax.xml.trans<strong>for</strong>m.Source source,<br />

javax.xml.trans<strong>for</strong>m.Result result)<br />

throws org.xml.sax.SAXException, java.io.IOException;<br />

Parameters<br />

source<br />

result<br />

<strong>XML</strong> to be validated. Must not be null.<br />

The javax.xml.trans<strong>for</strong>m.Result object that receives (possibly augmented) <strong>XML</strong>. This parameter can<br />

be null if the caller is not interested in it. Note that when a javax.xml.trans<strong>for</strong>m.dom.DOMResult is set<br />

and a validator does not modify the infoset, the input DOM tree still have to be copied by the validator.<br />

Exceptions<br />

IllegalArgumentException<br />

SAXException<br />

IOException<br />

NullPointerException<br />

If the javax.xml.trans<strong>for</strong>m.Result type doesn't match the javax.xml.trans<strong>for</strong>m.Source<br />

type, or if the specified source is neither javax.xml.trans<strong>for</strong>m.sax.SAXSource nor<br />

javax.xml.trans<strong>for</strong>m.dom.DOMSource.<br />

If the org.xml.sax.ErrorHandler throws a org.xml.sax.SAXException or if a fatal error<br />

is found and the org.xml.sax.ErrorHandler returns normally.<br />

If the validator is processing a javax.xml.trans<strong>for</strong>m.sax.SAXSource and the underlying<br />

org.xml.sax.<strong>XML</strong>Reader throws an java.io.IOException.<br />

If the<br />

source<br />

parameter is null.<br />

180


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

See Also<br />

javax.xml.validation.Validator.validate [Method validate(javax.xml.trans<strong>for</strong>m.Source)]<br />

Validates the specified input and send the augmented validation result to the specified output.<br />

This method places the following restrictions on the types of the javax.xml.trans<strong>for</strong>m.Source/ javax.xml.trans<strong>for</strong>m.Result<br />

accepted.<br />

javax.xml.trans<strong>for</strong>m.Source/javax.xml.trans<strong>for</strong>m.Result accepted:<br />

null<br />

javax.xml.trans<br />

<strong>for</strong>m.stream.StreamSource<br />

OK<br />

javax.xml.trans<br />

<strong>for</strong>m.sax.SAXSource<br />

OK<br />

javax.xml.trans<br />

<strong>for</strong>m.dom.DOMSource<br />

OK<br />

javax.xml.trans<br />

<strong>for</strong>m.stream.StreamResult<br />

Err<br />

Err<br />

Err<br />

javax.xml.trans<br />

<strong>for</strong>m.sax.SAXResult<br />

Err<br />

OK<br />

Err<br />

javax.xml.trans<br />

<strong>for</strong>m.dom.DOMResult<br />

Err<br />

Err<br />

OK<br />

To process javax.xml.trans<strong>for</strong>m.stream.StreamSource or to validate one javax.xml.trans<strong>for</strong>m.Source into another kind<br />

of javax.xml.trans<strong>for</strong>m.Result, use the identity trans<strong>for</strong>mer (see javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory.newTrans<br />

<strong>for</strong>mer)<br />

Errors found during the validation is sent to the specified org.xml.sax.ErrorHandler.<br />

If a document is valid, or if a document contains some errors but none of them were fatal and the org.xml.sax.ErrorHand<br />

ler didn't throw any exception, then the method returns normally.<br />

Class ValidatorHandler<br />

Streaming validator that works on SAX stream.<br />

A javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] object is a thread-unsafe, non-reentrant object. In<br />

other words, it is applications' responsibility to make sure that one javax.xml.validation.ValidatorHandler [ Class<br />

ValidatorHandler] object is not used from more than one thread at any given time.<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] checks if the SAX events follow the set of constraints<br />

described in the associated javax.xml.validation.Schema [ Class Schema], and additionally it may modifies the SAX<br />

events (<strong>for</strong> example by adding default values, etc.)<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] extends from org.xml.sax.ContentHandler, but it<br />

refines the underlying org.xml.sax.ContentHandler in the following way:<br />

1. startElement/endElement events must receive non-null String <strong>for</strong> uri, localName, and qname, even though<br />

SAX allows some of them to be null. Similarly, the user-specified callback will receive non-null Strings <strong>for</strong> all<br />

three parameters.<br />

2. Applications must ensure that javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]'s<br />

org.xml.sax.ContentHandler.startPrefixMapping and org.xml.sax.ContentHandler.endPrefixMapping are invoked<br />

properly.<br />

181


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

3. org.xml.sax.Attributes <strong>for</strong> the org.xml.sax.ContentHandler.startElement method may or may not include xmlns*<br />

attributes.<br />

A javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] is automatically reset every time the startDocument<br />

method is invoked.<br />

Recognized Properties and Features<br />

This spec defines the following feature that must be recognized by all javax.xml.validation.ValidatorHandler [ Class<br />

ValidatorHandler] implementations.<br />

http://xml.org/sax/features/namespace-prefixes<br />

Synopsis<br />

This feature controls how a javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] introduces namespace<br />

bindings that were not present in the original SAX event stream. When a new namespace binding is introduced by a<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler], it must invoke org.xml.sax.ContentHandler.startPre<br />

fixMapping and org.xml.sax.ContentHandler.endPrefixMapping methods of the org.xml.sax.ContentHandler specified<br />

by the user. Additionally, when this feature is set to true, it must also make sure that the user's org.xml.sax.ContentHand<br />

ler will see the corresponding xmlns* attribute in the org.xml.sax.Attributes object of the org.xml.sax.ContentHand<br />

ler.startElement callback.<br />

Note that this feature does NOT affect the way a javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] receives<br />

SAX events. It merely changes the way it augments SAX events.<br />

This feature is set to false by default.<br />

public ValidatorHandlerimplements ContentHandler {<br />

protected ValidatorHandler();<br />

public void abstract setContentHandler(org.xml.sax.ContentHandler receiver);<br />

public ContentHandler abstract getContentHandler();<br />

public boolean abstract isValidSoFar();<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

public ErrorHandler abstract getErrorHandler();<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

public LSResourceResolver abstract getResourceResolver();<br />

public TypeInfoProvider abstract getTypeInfoProvider();<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

182


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

}<br />

Author<br />

Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com]<br />

Version $Revision: 1.19 $, $Date: 2003/12/06 00:21:36 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.validation.ValidatorHandler<br />

Members<br />

Constructor ValidatorHandler()<br />

protected ValidatorHandler();<br />

Constructor <strong>for</strong> derived classes.<br />

The constructor does nothing.<br />

Derived classes should create javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] objects that have<br />

null<br />

org.xml.sax.ErrorHandler and<br />

null<br />

org.w3c.dom.ls.LSResourceResolver.<br />

Method getContentHandler()<br />

public ContentHandler abstract getContentHandler();<br />

See Also javax.xml.validation.ValidatorHandler.setContentHandler [Method setContentHand<br />

ler(org.xml.sax.ContentHandler)]<br />

Gets the org.xml.sax.ContentHandler which receives the augmented validation result.<br />

183


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Method getErrorHandler()<br />

public ErrorHandler abstract getErrorHandler();<br />

See Also<br />

javax.xml.validation.ValidatorHandler.setErrorHandler [Method setErrorHandler(org.xml.sax.Er<br />

rorHandler)]<br />

Gets the current org.xml.sax.ErrorHandler set to this javax.xml.validation.ValidatorHandler [ Class ValidatorHandler].<br />

Method getFeature(String)<br />

public boolean getFeature(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The feature name, which is a non-null fully-qualified URI.<br />

The current value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the feature value can't be assigned or retrieved.<br />

When the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] recognizes<br />

the feature name but cannot determine its value at this time.<br />

When the name parameter is null.<br />

See Also<br />

javax.xml.validation.ValidatorHandler.setFeature [Method setFeature(java.lang.String, boolean)]<br />

Look up the value of a feature flag.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler] to recognize a feature name but temporarily be unable to return its value. Some feature values may be<br />

available only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.<br />

Method getProperty(String)<br />

public Object getProperty(java.lang.String name)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

returns<br />

The property name, which is a non-null fully-qualified URI.<br />

The current value of the property.<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

If the property value can't be assigned or retrieved.<br />

184


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

When the <strong>XML</strong>Reader recognizes the property name but cannot determine its value at<br />

this time.<br />

When the name parameter is null.<br />

See Also javax.xml.validation.ValidatorHandler.setProperty [Method setProperty(java.lang.String,<br />

java.lang.Object)]<br />

Look up the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler] to recognize a property name but temporarily be unable to return its value. Some property values may be<br />

available only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]s are not required to recognize any specific property<br />

names.<br />

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.<br />

Method getResourceResolver()<br />

public LSResourceResolver abstract getResourceResolver();<br />

See Also<br />

javax.xml.validation.ValidatorHandler.setErrorHandler [Method setErrorHandler(org.xml.sax.Er<br />

rorHandler)]<br />

Gets the current org.w3c.dom.ls.LSResourceResolver set to this javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler].<br />

Method getTypeInfoProvider()<br />

public TypeInfoProvider abstract getTypeInfoProvider();<br />

Obtains the javax.xml.validation.TypeInfoProvider [ Class TypeInfoProvider] implementation of this javax.xml.valid<br />

ation.ValidatorHandler [ Class ValidatorHandler].<br />

The obtained javax.xml.validation.TypeInfoProvider [ Class TypeInfoProvider] can be queried during a parse to access<br />

the type in<strong>for</strong>mation determined by the validator.<br />

Some schema languages do not define the notion of type, <strong>for</strong> those languages, this method may not be supported.<br />

However, to be compliant with this specification, implementations <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 and <strong>XML</strong> 1.0 DTD<br />

must support this operation.<br />

Method isValidSoFar()<br />

public boolean abstract isValidSoFar();<br />

Returns true if the validator found no error up to this point.<br />

More precisely, this method returns true if and only if no error is found in the document since the last startDocument<br />

event was received.<br />

Method setContentHandler(ContentHandler)<br />

public void abstract setContentHandler(org.xml.sax.ContentHandler receiver);<br />

185


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

Parameters<br />

receiver<br />

A org.xml.sax.ContentHandler or a null value.<br />

Sets the org.xml.sax.ContentHandler which receives the augmented validation result.<br />

When a org.xml.sax.ContentHandler is specified, a javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]<br />

will work as a filter and basically copy the incoming events to the specified org.xml.sax.ContentHandler.<br />

In doing so, a javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] may modify the events, <strong>for</strong> example<br />

by adding defaulted attributes.<br />

A javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] may buffer events to certain extent, but to allow<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] to be used by a parser, the following requirement<br />

has to be met.<br />

1. When org.xml.sax.ContentHandler.startElement, org.xml.sax.ContentHandler.endElement, org.xml.sax.Con<br />

tentHandler.startDocument, or org.xml.sax.ContentHandler.endDocument are invoked on a javax.xml.valida<br />

tion.ValidatorHandler [ Class ValidatorHandler], the same method on the user-specified org.xml.sax.ContentHandler<br />

must be invoked <strong>for</strong> the same event be<strong>for</strong>e the callback returns.<br />

2. javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] may not introduce new elements that were not<br />

present in the input.<br />

3. javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] may not remove attributes that were present in<br />

the input.<br />

4. If javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] determines that certain characters are "ignorable<br />

whitespace", it should invoke the org.xml.sax.ContentHandler.ignorableWhitespace callback instead of the<br />

org.xml.sax.ContentHandler.characters callback. This is necessary <strong>for</strong> a javax.xml.parsers.DocumentBuilder to<br />

properly implement org.w3c.dom.Text.isElementContentWhitespace.<br />

When a callback method on the specified org.xml.sax.ContentHandler throws an exception, the same exception object<br />

must be thrown from the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]. The org.xml.sax.ErrorHandler<br />

should not be notified of such an exception.<br />

This method can be called even during a middle of a validation.<br />

Method setErrorHandler(ErrorHandler)<br />

public void abstract setErrorHandler(org.xml.sax.ErrorHandler errorHandler);<br />

Parameters<br />

errorHandler<br />

A new error handler to be set. This parameter can be null.<br />

Sets the org.xml.sax.ErrorHandler to receive errors encountered during the validation.<br />

Error handler can be used to customize the error handling process during a validation. When an org.xml.sax.ErrorHandler<br />

is set, errors found during the validation will be first sent to the org.xml.sax.ErrorHandler.<br />

The error handler can abort further validation immediately by throwing org.xml.sax.SAXException from the handler.<br />

Or <strong>for</strong> example it can print an error to the screen and try to continue the validation by returning normally from the<br />

org.xml.sax.ErrorHandler<br />

186


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

If any java.lang.Throwable is thrown from an org.xml.sax.ErrorHandler, the same java.lang.Throwable object will<br />

be thrown toward the root of the call stack.<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] is not allowed to throw org.xml.sax.SAXException<br />

without first reporting it to org.xml.sax.ErrorHandler.<br />

When the org.xml.sax.ErrorHandler is null, the implementation will behave as if the following org.xml.sax.ErrorHandler<br />

is set:<br />

class DraconianErrorHandler implements<br />

org.xml.sax.ErrorHandler {<br />

public void fatalError(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

public void error(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

throw e;<br />

}<br />

public void warning(<br />

org.xml.sax.SAXParseException e ) throws<br />

org.xml.sax.SAXException {<br />

// noop<br />

}<br />

}<br />

When a new javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] object is created, initially this field is<br />

set to null.<br />

Method setFeature(String, boolean)<br />

public void setFeature(java.lang.String name,<br />

boolean value)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

value<br />

The feature name, which is a non-null fully-qualified URI.<br />

The requested value of the feature (true or false).<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

If the feature value can't be assigned or retrieved.<br />

When the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] recognizes<br />

the feature name but cannot set the requested value.<br />

187


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

NullPointerException<br />

When the name parameter is null.<br />

See Also<br />

javax.xml.validation.ValidatorHandler.getFeature [Method getFeature(java.lang.String)]<br />

Set the value of a feature flag.<br />

Feature can be used to control the way a javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] parses<br />

schemas, although javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]s are not required to recognize any<br />

specific property names.<br />

The feature name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler] to expose a feature value but to be unable to change the current value. Some feature values may be im<br />

mutable or mutable only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

Method setProperty(String, Object)<br />

public void setProperty(java.lang.String name,<br />

java.lang.Object object)<br />

throws org.xml.sax.SAXNotRecognizedException, org.xml.sax.SAXNotSupportedException;<br />

Parameters<br />

name<br />

object<br />

The property name, which is a non-null fully-qualified URI.<br />

The requested value <strong>for</strong> the property.<br />

Exceptions<br />

org.xml.sax.SAXNotRe<br />

cognizedException<br />

org.xml.sax.SAXNotSup<br />

portedException<br />

NullPointerException<br />

If the property value can't be assigned or retrieved.<br />

When the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] recognizes<br />

the property name but cannot set the requested value.<br />

When the name parameter is null.<br />

Set the value of a property.<br />

The property name is any fully-qualified URI. It is possible <strong>for</strong> a javax.xml.validation.ValidatorHandler [ Class Valid<br />

atorHandler] to recognize a property name but to be unable to change the current value. Some property values may be<br />

immutable or mutable only in specific contexts, such as be<strong>for</strong>e, during, or after a validation.<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler]s are not required to recognize setting any specific<br />

property names.<br />

Method setResourceResolver(LSResourceResolver)<br />

public void abstract setResourceResolver(org.w3c.dom.ls.LSResourceResolver resourceResolv<br />

Parameters<br />

resourceResolver<br />

A new resource resolver to be set. This parameter can be null.<br />

Sets the org.w3c.dom.ls.LSResourceResolver to customize resource resolution while in a validation episode.<br />

188


Community Draft<br />

Package javax.xml.validation<br />

Community Draft<br />

javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] uses a org.w3c.dom.ls.LSResourceResolver when it<br />

needs to locate external resources while a validation, although exactly what constitutes "locating external resources"<br />

is up to each schema language.<br />

When the org.w3c.dom.ls.LSResourceResolver is null, the implementation will behave as if the following<br />

org.w3c.dom.ls.LSResourceResolver is set:<br />

class DumbLSResourceResolver implements<br />

org.w3c.dom.ls.LSResourceResolver {<br />

public<br />

org.w3c.dom.ls.LSInput resolveResource(<br />

String publicId, String systemId, String baseURI) {<br />

}<br />

}<br />

return null; // always return null<br />

If a org.w3c.dom.ls.LSResourceResolver throws a java.lang.RuntimeException (or instances of its derived classes),<br />

then the javax.xml.validation.ValidatorHandler [ Class ValidatorHandler] will abort the parsing and the caller of the<br />

validate method will receive the same java.lang.RuntimeException. When a new javax.xml.validation.Validat<br />

orHandler [ Class ValidatorHandler] object is created, initially this field is set to null.<br />

189


Community Draft<br />

Community Draft<br />

Chapter 16. Package javax.xml.datatype<br />

Class Duration<br />

Immutable representation of a time span as defined in the W3C <strong>XML</strong> Schema 1.0 specification.<br />

A Duration object represents a period of Gregorian time, which consists of six fields (years, months, days, hours,<br />

minutes, and seconds) plus a sign (+/-) field.<br />

The first five fields have non-negative (>=0) integers or null (which represents that the field is not set), and the seconds<br />

field has a non-negative decimal or null. A negative sign indicates a negative duration.<br />

This class provides a number of methods that make it easy to use <strong>for</strong> the duration datatype of <strong>XML</strong> Schema 1.0 with<br />

the errata.<br />

Order relationship<br />

Duration objects only have partial order, where two values A and B maybe either:<br />

1. AB (A is longer than B)<br />

3. A==B (A and B are of the same duration)<br />

4. AB (Comparison between A and B is indeterminate)<br />

For example, 30 days cannot be meaningfully compared to one month. The javax.xml.datatype.Duration.compare [<br />

Method compare(javax.xml.datatype.Duration, javax.xml.datatype.Duration)] method implements this relationship.<br />

See the javax.xml.datatype.Duration.isLongerThan [ Method isLongerThan(javax.xml.datatype.Duration)] method <strong>for</strong><br />

details about the order relationship among javax.xml.datatype.Duration [ Class Duration] objects.<br />

Operations over Duration<br />

This class provides a set of basic arithmetic operations, such as addition, subtraction and multiplication. Because dur<br />

ations don't have total order, an operation could fail <strong>for</strong> some combinations of operations. For example, you cannot<br />

subtract 15 days from 1 month. See the javadoc of those methods <strong>for</strong> detailed conditions where this could happen.<br />

Also, division of a duration by a number is not provided because the javax.xml.datatype.Duration [ Class Duration]<br />

class can only deal with finite precision decimal numbers. For example, one cannot represent 1 sec divided by 3.<br />

However, you could substitute a division by 3 with multiplying by numbers such as 0.3 or 0.333.<br />

Range of allowed values<br />

Because some operations of javax.xml.datatype.Duration [ Class Duration] rely on java.util.Calendar even though<br />

javax.xml.datatype.Duration [ Class Duration] can hold very large or very small values, some of the methods may not<br />

work correctly on such javax.xml.datatype.Duration [ Class Duration]s. The impacted methods document their depend<br />

ency on java.util.Calendar.<br />

190


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Synopsis<br />

public Durationimplements Serializable {<br />

public Duration(boolean isPositive,<br />

java.math.BigInteger years,<br />

java.math.BigInteger months,<br />

java.math.BigInteger days,<br />

java.math.BigInteger hours,<br />

java.math.BigInteger minutes,<br />

java.math.BigDecimal seconds);<br />

public Duration(boolean isPositive,<br />

int years,<br />

int months,<br />

int days,<br />

int hours,<br />

int minutes,<br />

int seconds);<br />

public Duration(long durationInMilliSeconds);<br />

public Duration(java.lang.String lexicalRepresentation)<br />

throws java.lang.IllegalArgumentException;<br />

static int compare(javax.xml.datatype.Duration lhs,<br />

javax.xml.datatype.Duration rhs);<br />

final boolean isLongerThan(javax.xml.datatype.Duration rhs);<br />

final boolean isShorterThan(javax.xml.datatype.Duration rhs);<br />

final boolean equals(java.lang.Object rhs);<br />

public int hashCode();<br />

public String toString();<br />

public boolean isSet(javax.xml.datatype.Duration.Field field);<br />

public Number getField(javax.xml.datatype.Duration.Field field);<br />

public int getYears();<br />

public int getMonths();<br />

public int getDays();<br />

public int getHours();<br />

public int getMinutes();<br />

public int getSeconds();<br />

final long getTimeInMillis(java.util.Calendar startInstant);<br />

191


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

final long getTimeInMillis(java.util.Date startInstant);<br />

public Duration normalizeWith(java.util.Calendar startTimeInstant);<br />

public Duration multiply(int factor);<br />

final Duration multiply(java.math.BigDecimal factor);<br />

final Duration add(javax.xml.datatype.Duration rhs);<br />

final Duration subtract(javax.xml.datatype.Duration rhs);<br />

public Duration negate();<br />

public int signum();<br />

public void addTo(java.util.Calendar calendar);<br />

public void addTo(java.util.Date date);<br />

}<br />

Author Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com], Joseph Fialli<br />

[mailto:Joseph.Fialli@Sun.com]<br />

Version $Revision: <strong>1.3</strong>3 $, $Date: 2003/12/11 20:58:53 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.add [Method add(javax.xml.datatype.Duration)]<br />

java.lang.Object<br />

|<br />

javax.xml.datatype.Duration<br />

Members<br />

Constructor Duration(boolean, BigInteger, BigInteger, BigInteger, BigInteger,<br />

BigInteger, BigDecimal)<br />

public Duration(boolean isPositive,<br />

java.math.BigInteger years,<br />

java.math.BigInteger months,<br />

java.math.BigInteger days,<br />

java.math.BigInteger hours,<br />

java.math.BigInteger minutes,<br />

java.math.BigDecimal seconds);<br />

Parameters<br />

isPositive<br />

Set to false to create a negative duration. When the length of the duration is zero, this<br />

parameter will be ignored.<br />

192


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

years<br />

months<br />

days<br />

hours<br />

minutes<br />

seconds<br />

Exceptions<br />

of this Duration<br />

of this Duration<br />

of this Duration<br />

of this Duration<br />

of this Duration<br />

of this Duration<br />

IllegalArgumentException<br />

If years, months, days, hours, minutes and seconds parameters are all null. Or if any<br />

of those parameters are negative.<br />

Constructs a new Duration object by specifying each field individually.<br />

All the parameters are optional as long as at least one field is present. If specified, parameters have to be zero or positive.<br />

Constructor Duration(boolean, int, int, int, int, int, int)<br />

public Duration(boolean isPositive,<br />

int years,<br />

int months,<br />

int days,<br />

int hours,<br />

int minutes,<br />

int seconds);<br />

See Also<br />

javax.xml.datatype.Duration [Constructor Duration(boolean, java.math.BigInteger, java.math.Bi<br />

gInteger, java.math.BigInteger, java.math.BigInteger, java.math.BigInteger, java.math.BigDecimal)]<br />

Constructs a new Duration object by specifying each field individually.<br />

This method is functionally equivalent to invoking another constructor by wrapping all non-zero parameters into<br />

java.math.BigInteger and java.math.BigDecimal. Zero value of int parameter is equivalent of null value of the corres<br />

ponding field.<br />

Constructor Duration(long)<br />

public Duration(long durationInMilliSeconds);<br />

Parameters<br />

durationInMilliSeconds<br />

The length of the duration in milliseconds.<br />

Constructs a new Duration object by specifying the duration in milliseconds.<br />

The DAYS, HOURS, MINUTES and SECONDS fields are used to represent the specifed duration in a reasonable<br />

way. That is, the constructed object x satisfies the following conditions:<br />

• x.getHours()


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

• x.getSeconds()


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Field HOURS<br />

Partial order relation comparison result.<br />

static javax.xml.datatype.Duration.Field HOURS ;<br />

A constant that represents the hours field.<br />

Field INDETERMINATE<br />

Field LESSER<br />

static int INDETERMINATE ;<br />

See Also javax.xml.datatype.Duration.compare [Method compare(javax.xml.datatype.Duration,<br />

javax.xml.datatype.Duration)]<br />

Partial order relation comparison result.<br />

static int LESSER ;<br />

See Also javax.xml.datatype.Duration.compare [Method compare(javax.xml.datatype.Duration,<br />

javax.xml.datatype.Duration)]<br />

Partial order relation comparison result.<br />

Field MINUTES<br />

static javax.xml.datatype.Duration.Field MINUTES ;<br />

A constant that represents the minutes field.<br />

Field MONTHS<br />

static javax.xml.datatype.Duration.Field MONTHS ;<br />

A constant that represents the months field.<br />

Field SECONDS<br />

Field YEARS<br />

static javax.xml.datatype.Duration.Field SECONDS ;<br />

A constant that represents the seconds field.<br />

static javax.xml.datatype.Duration.Field YEARS ;<br />

A constant that represents the years field.<br />

Method add(Duration)<br />

final Duration add(javax.xml.datatype.Duration rhs);<br />

195


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Parameters<br />

rhs<br />

returns<br />

Exceptions<br />

Duration to add to this Duration<br />

non-null valid Duration object.<br />

NullPointerException<br />

IllegalStateException<br />

If the rhs parameter is null.<br />

If two durations cannot be meaningfully added. For example, adding negative one day<br />

to one month causes this exception.<br />

See Also<br />

javax.xml.datatype.Duration.subtract [Method subtract(javax.xml.datatype.Duration)]<br />

Computes a new duration whose value is this+rhs.<br />

For example,<br />

"1 day" + "-3 days" = "-2 days"<br />

"1 year" + "1 day" = "1 year and 1 day"<br />

"-(1 hour,50 minutes)" + "-20 minutes" = "-(1 hours,70 minutes)"<br />

"15 hours" + "-3 days" = "-(2 days,9 hours)"<br />

"1 year" + "-1 day" = IllegalStateException<br />

Since there's no way to meaningfully subtract 1 day from 1 month, there are cases where the operation fails in<br />

java.lang.IllegalStateException. Formally, the computation is defined as follows. Firstly, we can assume that two<br />

javax.xml.datatype.Duration [ Class Duration]s to be added are both positive without losing generality (i.e., (-X)+Y=Y-<br />

X, X+(-Y)=X-Y, (-X)+(-Y)=-(X+Y)) Addition of two positive javax.xml.datatype.Duration [ Class Duration]s<br />

are simply defined as field by field addition where missing fields are treated as 0. A field of the resulting<br />

javax.xml.datatype.Duration [ Class Duration] will be unset if and only if respective fields of two input<br />

javax.xml.datatype.Duration [ Class Duration]s are unset. Note that lhs.add(rhs) will be always successful if<br />

lhs.signum()*rhs.signum()!=-1 or both of them are normalized.<br />

Method addTo(Calendar)<br />

public void addTo(java.util.Calendar calendar);<br />

Parameters<br />

calendar<br />

A calendar object whose value will be modified.<br />

Exceptions<br />

NullPointerException<br />

if the calendar parameter is null.<br />

Adds this duration to a java.util.Calendar object.<br />

Calls java.util.Calendar.add in the order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MIL<br />

LISECONDS if those fields are present. Because the java.util.Calendar class uses int to hold values, there are cases<br />

where this method won't work correctly (<strong>for</strong> example if values of fields exceed the range of int.)<br />

196


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Also, since this duration class is a Gregorian duration, this method will not work correctly if the given java.util.Calendar<br />

object is based on some other calendar systems.<br />

Any fractional parts of this javax.xml.datatype.Duration [ Class Duration] object beyond milliseconds will be simply<br />

ignored. For example, if this duration is "P1.23456S", then 1 is added to SECONDS, 234 is added to MILLISECONDS,<br />

and the rest will be unused.<br />

Note that because java.util.Calendar.add is using<br />

int<br />

, javax.xml.datatype.Duration [ Class Duration] with values beyond the range of<br />

int<br />

in its fields will cause overflow/underflow to the given java.util.Calendar. javax.xml.datatype.<strong>XML</strong>GregorianCalen<br />

dar.add [ Method add(javax.xml.datatype.Duration)] provides the same basic operation as this method while avoiding<br />

the overflow/underflow issues.<br />

Method addTo(Date)<br />

public void addTo(java.util.Date date);<br />

Parameters<br />

date<br />

A date object whose value will be modified.<br />

Exceptions<br />

NullPointerException<br />

if the date parameter is null.<br />

Adds this duration to a java.util.Date object.<br />

The given date is first converted into a java.util.GregorianCalendar, then the duration is added exactly like the<br />

javax.xml.datatype.Duration.addTo [ Method addTo(java.util.Calendar)] method.<br />

The updated time instant is then converted back into a java.util.Date object and used to update the given java.util.Date<br />

object.<br />

This somewhat redundant computation is necessary to unambiguously determine the duration of months and years.<br />

Method compare(Duration, Duration)<br />

static int compare(javax.xml.datatype.Duration lhs,<br />

javax.xml.datatype.Duration rhs);<br />

Parameters<br />

lhs<br />

rhs<br />

instance of Duration to compare<br />

instance of Duration to compare<br />

197


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

returns<br />

the relationship between lhs and rhs as javax.xml.datatype.Duration.LESSER [ Field LESSER],<br />

javax.xml.datatype.Duration.EQUAL [ Field EQUAL], javax.xml.datatype.Duration.GREATER [<br />

Field GREATER] or javax.xml.datatype.Duration.INDETERMINATE [ Field INDETERMINATE].<br />

Exceptions<br />

NullPointerException<br />

if lhs or rhs parameters are null.<br />

See Also<br />

javax.xml.datatype.Duration.isShorterThan [Method isShorterThan(javax.xml.datatype.Duration)],<br />

javax.xml.datatype.Duration.isLongerThan [Method isLongerThan(javax.xml.datatype.Duration)]<br />

Partial order relation comparison between two Duration instances.<br />

Comparison result must be in accordance with W3C <strong>XML</strong> Schema 1.0 Part 2, Section 3.2.7.6.2, Order relation on<br />

duration [http://www.w3.org/TR/xmlschema-2/#duration-order].<br />

Method equals(Object)<br />

final boolean equals(java.lang.Object rhs);<br />

Parameters<br />

rhs<br />

returns<br />

A non-null valid javax.xml.datatype.Duration [ Class Duration] object.<br />

true if this duration is the same length as rhs. false if rhs is not a javax.xml.datatype.Duration<br />

[ Class Duration] object or its length is different from this duration.<br />

Exceptions<br />

NullPointerException<br />

if parameter is null.<br />

See Also javax.xml.datatype.Duration.compare [Method compare(javax.xml.datatype.Duration,<br />

javax.xml.datatype.Duration)]<br />

Checks if this duration object has the same duration as another javax.xml.datatype.Duration [ Class Duration] object.<br />

For example, "P1D" (1 day) is equal to "PT24H" (24 hours).<br />

Duration X is equal to Y if and only if time instant t+X and t+Y are the same <strong>for</strong> all the test time instants specified in<br />

the section 3.2.6.2 of the <strong>XML</strong> Schema 1.0 specification.<br />

Note that there are cases where two javax.xml.datatype.Duration [ Class Duration]s are "incomparable" to each other,<br />

like one month and 30 days. For example,<br />

!new Duration("P1M").isShorterThan(new Duration("P30D"))<br />

!new Duration("P1M").isLongerThan(new Duration("P30D"))<br />

!new Duration("P1M").equals(new Duration("P30D"))<br />

Method getDays()<br />

public int getDays();<br />

198


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Obtains the value of the DAYS field as an integer value, or 0 if not present. This method works just like<br />

javax.xml.datatype.Duration.getYears [ Method getYears()] except that this method works on the DAYS field.<br />

Method getField(Duration.Field)<br />

public Number getField(javax.xml.datatype.Duration.Field field);<br />

Parameters<br />

field<br />

returns<br />

one of the six Field constants (YEARS,MONTHS,DAYS,HOURS, MINUTES, or SECONDS.)<br />

If the specified field is present, this method returns a non-null non-negative java.lang.Number object<br />

that represents its value. If it is not present, return null. For YEARS, MONTHS, DAYS, HOURS,<br />

and MINUTES, this method returns a java.math.BigInteger object. For SECONDS, this method returns<br />

a java.math.BigDecimal.<br />

Exceptions<br />

NullPointerException<br />

If the field parameter is null.<br />

Gets the value of a field. Fields of a duration object may contain arbitrary large value. There<strong>for</strong>e this method is designed<br />

to return a java.lang.Number object. In case of YEARS, MONTHS, DAYS, HOURS, and MINUTES, the returned<br />

number will be a non-negative integer. In case of seconds, the returned number may be a non-negative decimal value.<br />

Method getHours()<br />

public int getHours();<br />

Obtains the value of the HOURS field as an integer value, or 0 if not present. This method works just like<br />

javax.xml.datatype.Duration.getYears [ Method getYears()] except that this method works on the HOURS field.<br />

Method getMinutes()<br />

public int getMinutes();<br />

Obtains the value of the MINUTES field as an integer value, or 0 if not present. This method works just like<br />

javax.xml.datatype.Duration.getYears [ Method getYears()] except that this method works on the MINUTES field.<br />

Method getMonths()<br />

public int getMonths();<br />

Obtains the value of the MONTHS field as an integer value, or 0 if not present. This method works just like<br />

javax.xml.datatype.Duration.getYears [ Method getYears()] except that this method works on the MONTHS field.<br />

Method getSeconds()<br />

public int getSeconds();<br />

Obtains the value of the SECONDS field as an integer value, or 0 if not present. This method works just like<br />

javax.xml.datatype.Duration.getYears [ Method getYears()] except that this method works on the SECONDS field.<br />

199


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method getTimeInMillis(Calendar)<br />

final long getTimeInMillis(java.util.Calendar startInstant);<br />

Parameters<br />

startInstant<br />

returns<br />

The length of a month/year varies. The startInstant is used to disambiguate this<br />

variance. Specifically, this method returns the difference between startInstant and<br />

startInstant+duration<br />

milliseconds between startInstant and startInstant plus this Duration<br />

Exceptions<br />

NullPointerException<br />

if startInstant parameter is null.<br />

Returns the length of the duration in milli-seconds.<br />

If the seconds field carries more digits than milli-second order, those will be simply discarded (or in other words,<br />

rounded to zero.) For example, <strong>for</strong> any Calendar value x,<br />

new Duration("PT10.00099S").getTimeInMills(x) == 10000.<br />

new Duration("-PT10.00099S").getTimeInMills(x) == -10000.<br />

Note that this method uses the javax.xml.datatype.Duration.addTo [ Method addTo(java.util.Calendar)] method, which<br />

may work incorectly with javax.xml.datatype.Duration [ Class Duration] objects with very large values in its fields.<br />

See the javax.xml.datatype.Duration.addTo [ Method addTo(java.util.Calendar)] method <strong>for</strong> details.<br />

Method getTimeInMillis(Date)<br />

final long getTimeInMillis(java.util.Date startInstant);<br />

Parameters<br />

startInstant<br />

returns<br />

The length of a month/year varies. The startInstant is used to disambiguate this<br />

variance. Specifically, this method returns the difference between startInstant and<br />

startInstant+duration.<br />

milliseconds between startInstant and startInstant plus this Duration<br />

Exceptions<br />

NullPointerException<br />

If the startInstant parameter is null.<br />

See Also<br />

javax.xml.datatype.Duration.getTimeInMillis [Method getTimeInMillis(java.util.Calendar)]<br />

Returns the length of the duration in milli-seconds.<br />

200


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

If the seconds field carries more digits than milli-second order, those will be simply discarded (or in other words,<br />

rounded to zero.) For example, <strong>for</strong> any Date value x,<br />

new Duration("PT10.00099S").getTimeInMills(x) == 10000.<br />

new Duration("-PT10.00099S").getTimeInMills(x) == -10000.<br />

Note that this method uses the javax.xml.datatype.Duration.addTo [ Method addTo(java.util.Date)] method, which<br />

may work incorectly with javax.xml.datatype.Duration [ Class Duration] objects with very large values in its fields.<br />

See the javax.xml.datatype.Duration.addTo [ Method addTo(java.util.Date)] method <strong>for</strong> details.<br />

Method getYears()<br />

public int getYears();<br />

Obtains the value of the YEARS field as an integer value, or 0 if not present.<br />

This method is a convenience method around the javax.xml.datatype.Duration.getField [ Method getField(javax.xml.data<br />

type.Duration.Field)] method.<br />

Note that since this method returns<br />

int<br />

, this method will return an incorrect value <strong>for</strong> javax.xml.datatype.Duration [ Class Duration]s with the year field that<br />

goes beyond the range of<br />

int<br />

. Use getField(YEARS) to avoid possible loss of precision.<br />

Method hashCode()<br />

public int hashCode();<br />

See Also<br />

java.lang.Object.hashCode<br />

Returns a hash code consistent with the definition of the equals method.<br />

Method isLongerThan(Duration)<br />

final boolean isLongerThan(javax.xml.datatype.Duration rhs);<br />

Parameters<br />

rhs<br />

A non-null valid Duration instance.<br />

201


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

returns<br />

true if the duration represented by this object is longer than the given duration. false otherwise.<br />

Exceptions<br />

NullPointerException<br />

if the rhs parameter is null.<br />

See Also<br />

javax.xml.datatype.Duration.isShorterThan [Method isShorterThan(javax.xml.datatype.Duration)],<br />

javax.xml.datatype.Duration.compare [Method compare(javax.xml.datatype.Duration,<br />

javax.xml.datatype.Duration)]<br />

Checks if this duration object is strictly longer than another javax.xml.datatype.Duration [ Class Duration] object.<br />

Duration X is "longer" than Y if and only if X>Y as defined in the section 3.2.6.2 of the <strong>XML</strong> Schema 1.0 specification.<br />

For example, "P1D" (one day) > "PT12H" (12 hours) and "P2Y" (two years) > "P23M" (23 months).<br />

Method isSet(Duration.Field)<br />

public boolean isSet(javax.xml.datatype.Duration.Field field);<br />

Parameters<br />

field<br />

returns<br />

one of the six Field constants (YEARS,MONTHS,DAYS,HOURS, MINUTES, or SECONDS.)<br />

true if the field is present. false if not.<br />

Exceptions<br />

NullPointerException<br />

If the field parameter is null.<br />

Checks if a field is set. A field of a duration object may or may not be present. This method can be used to test if a<br />

field is present.<br />

Method isShorterThan(Duration)<br />

final boolean isShorterThan(javax.xml.datatype.Duration rhs);<br />

Parameters<br />

rhs<br />

returns<br />

Duration to test this Duration against.<br />

true if Duration parameter is shorter than this Duration, else false.<br />

Exceptions<br />

NullPointerException<br />

if parameter is null.<br />

See Also<br />

javax.xml.datatype.Duration.isLongerThan [Method isLongerThan(javax.xml.datatype.Duration)],<br />

javax.xml.datatype.Duration.compare [Method compare(javax.xml.datatype.Duration,<br />

javax.xml.datatype.Duration)]<br />

Checks if this duration object is strictly shorter than another javax.xml.datatype.Duration [ Class Duration] object.<br />

This method is really just a convenience method of rhs.isLongerThan(this).<br />

202


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method multiply(BigDecimal)<br />

final Duration multiply(java.math.BigDecimal factor);<br />

Parameters<br />

factor<br />

returns<br />

to multiply by<br />

returns a non-null valid javax.xml.datatype.Duration [ Class Duration] object<br />

Exceptions<br />

IllegalStateException<br />

NullPointerException<br />

if operation produces fraction in the months field.<br />

if the factor parameter is null.<br />

Computes a new duration whose value is factor times longer than the value of this duration.<br />

For example,<br />

"P1M" (1 month) * "12" = "P12M" (12 months)<br />

"PT1M" (1 min) * "0.3" = "PT18S" (18 seconds)<br />

"P1M" (1 month) * "1.5" = IllegalStateException<br />

Since the javax.xml.datatype.Duration [ Class Duration] class is immutable, this method doesn't change the value of<br />

this object. It simply computes a new Duration object and returns it. The operation will be per<strong>for</strong>med field by field<br />

with the precision of java.math.BigDecimal. Since all the fields except seconds are restricted to hold integers, any<br />

fraction produced by the computation will be carried down toward the next lower unit. For example, if you multiply<br />

"P1D" (1 day) with "0.5", then it will be 0.5 day, which will be carried down to "PT12H" (12 hours). When fractions<br />

of month cannot be meaningfully carried down to days, or year to months, this will cause an java.lang.IllegalStateEx<br />

ception to be thrown. For example if you multiple one month by 0.5. To avoid java.lang.IllegalStateException, use<br />

the javax.xml.datatype.Duration.normalizeWith [ Method normalizeWith(java.util.Calendar)] method to remove the<br />

years and months fields.<br />

Method multiply(int)<br />

public Duration multiply(int factor);<br />

Parameters<br />

factor<br />

returns<br />

See Also<br />

Factor times longer of new Duration to create.<br />

New Duration that is factortimes longer than this Duration.<br />

javax.xml.datatype.Duration.multiply [Method multiply(java.math.BigDecimal)]<br />

Computes a new duration whose value is factor times longer than the value of this duration.<br />

This method is provided <strong>for</strong> the convenience. It is functionally equivalent to the following code:<br />

203


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

multiply(new BigDecimal(String.valueOf(factor)))<br />

Method negate()<br />

public Duration negate();<br />

Returns a new javax.xml.datatype.Duration [ Class Duration] object whose value is -this.<br />

Since the javax.xml.datatype.Duration [ Class Duration] class is immutable, this method doesn't change the value of<br />

this object. It simply computes a new Duration object and returns it.<br />

Method normalizeWith(Calendar)<br />

public Duration normalizeWith(java.util.Calendar startTimeInstant);<br />

Parameters<br />

startTimeInstant<br />

returns<br />

Calendar reference point.<br />

Duration of years and months of this Duration as days.<br />

Exceptions<br />

NullPointerException<br />

If the startTimeInstant parameter is null.<br />

Converts the years and months fields into the days field by using a specific time instant as the reference point.<br />

For example, duration of one month normalizes to 31 days given the start time instance "July 8th 2003, 17:40:32".<br />

Formally, the computation is done as follows:<br />

1. The given Calendar object is cloned.<br />

2. The years, months and days fields will be added to the java.util.Calendar object by using the java.util.Calendar.add<br />

method.<br />

3. The difference between two Calendars are computed in terms of days.<br />

4. The computed days, along with the hours, minutes and seconds fields of this duration object is used to construct<br />

a new Duration object.<br />

Note that since the Calendar class uses int to hold the value of year and month, this method may produce an unexpected<br />

result if this duration object holds a very large value in the years or months fields.<br />

Method signum()<br />

public int signum();<br />

Returns the sign of this duration in -1,0, or 1.<br />

204


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method subtract(Duration)<br />

final Duration subtract(javax.xml.datatype.Duration rhs);<br />

Parameters<br />

rhs<br />

returns<br />

Duration to substract from this Duration.<br />

New Duration created from subtracting rhs from this Duration.<br />

Exceptions<br />

IllegalStateException<br />

NullPointerException<br />

If two durations cannot be meaningfully subtracted. For example, subtracting one day<br />

from one month causes this exception.<br />

If the rhs parameter is null.<br />

See Also<br />

javax.xml.datatype.Duration.add [Method add(javax.xml.datatype.Duration)]<br />

Computes a new duration whose value is this-rhs.<br />

For example:<br />

"1 day" - "-3 days" = "4 days"<br />

"1 year" - "1 day" = IllegalStateException<br />

"-(1 hour,50 minutes)" - "-20 minutes" = "-(1hours,30 minutes)"<br />

"15 hours" - "-3 days" = "3 days and 15 hours"<br />

"1 year" - "-1 day" = "1 year and 1 day"<br />

Since there's no way to meaningfully subtract 1 day from 1 month, there are cases where the operation fails in<br />

java.lang.IllegalStateException.Formally the computation is defined as follows. First, we can assume that two<br />

javax.xml.datatype.Duration [ Class Duration]s are both positive without losing generality. (i.e., (-X)-Y=-(X+Y),<br />

X-(-Y)=X+Y, (-X)-(-Y)=-(X-Y))Then two durations are subtracted field by field. If the sign of any non-zero<br />

field<br />

F<br />

is different from the sign of the most significant field, 1 (if<br />

F<br />

is negative) or -1 (otherwise) will be borrowed from the next bigger unit of<br />

F<br />

205


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

.This process is repeated until all the non-zero fields have the same sign.If a borrow occurs in the days field (in other<br />

words, if the computation needs to borrow 1 or -1 month to compensate days), then the computation fails by throwing<br />

an java.lang.IllegalStateException.<br />

Method toString()<br />

public String toString();<br />

Returns a string representation of this duration object.<br />

The result is <strong>for</strong>matter according to the <strong>XML</strong> Schema 1.0 spec and can be always parsed back later into the equivalent<br />

duration object by the javax.xml.datatype.Duration [ Constructor Duration(java.lang.String)] constructor.<br />

Formally, the following holds <strong>for</strong> any javax.xml.datatype.Duration [ Class Duration] object x.<br />

new Duration(x.toString()).equals(x)<br />

Class Duration.Field<br />

Synopsis<br />

Type-safe enum class that represents six fields of the javax.xml.datatype.Duration [ Class Duration] class.<br />

static Duration.Field {<br />

public String toString();<br />

}<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.datatype.Duration.Field<br />

Members<br />

Method toString()<br />

public String toString();<br />

Returns a field name in English. This method is intended to be used <strong>for</strong> debugging/diagnosis and not <strong>for</strong> display to<br />

end-users.<br />

Class <strong>XML</strong>GregorianCalendar<br />

Representation <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 date/time datatypes. Specifically, these date/time datatypes are dateTime<br />

[#DATETIME], time [#TIME], date [#DATE], gYearMonth [#GYEARMONTH], gMonthDay<br />

<strong>206</strong>


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

[#GMONTHDAY], gYear [#GYEAR] gMonth [#GMONTH] and gDay [#GDAY] defined in the <strong>XML</strong> Namespace<br />

"http://www.w3.org/2001/<strong>XML</strong>Schema". These datatypes are normatively defined in W3C <strong>XML</strong> Schema<br />

1.0 Part 2, Section 3.2.7-14 [http://www.w3.org/TR/xmlschema-2/#dateTime].<br />

The table below defines the mapping between <strong>XML</strong> Schema 1.0 date/time datatype fields and this class' fields. It also<br />

summarizes the value constraints <strong>for</strong> the date and time fields defined in W3C <strong>XML</strong> Schema 1.0 Part 2, Appendix D,<br />

ISO 8601 Date and Time Formats [http://www.w3.org/TR/xmlschema-2/#iso<strong>for</strong>mats].<br />

Date/time datatype field mapping between <strong>XML</strong> Schema 1.0 and <strong>Java</strong> representation<br />

<strong>XML</strong> Schema 1.0 datatype<br />

field<br />

Related<strong>XML</strong>GregorianCalen<br />

darAccessor(s)<br />

Value Range<br />

year<br />

month<br />

day<br />

hour<br />

javax.xml.datatype.<strong>XML</strong> getYear() is a value<br />

GregorianCalendar.getYear between -(10^9-1) to (10^9)-<br />

[Method getYear()] + 1 or javax.xml.datatype.XM<br />

javax.xml.datatype.<strong>XML</strong> LGregorianCalen<br />

GregorianCalendar.getEon dar.FIELD_UNDEFINED<br />

[Method getEon()] or [Field FIELD_UN<br />

javax.xml.datatype.<strong>XML</strong> DEFINED].javax.xml.data<br />

GregorianCalen type.<strong>XML</strong>GregorianCalen<br />

dar.getEonAndYear [Method dar.getEon [Method<br />

getEonAndYear()] getEon()] is high order year<br />

value in billion of<br />

years.getEon() has values<br />

greater than or equal to<br />

(10^9) or less than or equal<br />

to -(10^9). A value of null<br />

indicates field is undefined.<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.getMonth<br />

[Method getMonth()]<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.getDay<br />

[Method getDay()]<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.getHour<br />

[Method getHour()]<br />

1 to 12 or javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED]<br />

Independent of month, max<br />

range is 1 to 31 or<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED]. The normative<br />

value constraint stated relat<br />

ive to month field's value is<br />

in W3C <strong>XML</strong> Schema 1.0<br />

Part 2, Appendix D<br />

[htp:/www.w3.org/TR/xmlschema-2/#iso<strong>for</strong>mats].<br />

0 to 23 or javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED]<br />

207


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Date/time datatype field mapping between <strong>XML</strong> Schema 1.0 and <strong>Java</strong> representation<br />

minute<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.get<br />

Minute [Method get<br />

Minute()]<br />

0 to 59 or javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED]<br />

second<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.get<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.get<br />

Second [Method get Second [Method get<br />

Second()] + javax.xml.data Second()] from 0 to 60 or<br />

type.<strong>XML</strong>GregorianCalen javax.xml.datatype.<strong>XML</strong><br />

dar.getMillisecond [Method GregorianCalen<br />

getMillisecond()]/1000 or dar.FIELD_UNDEFINED<br />

javax.xml.datatype.<strong>XML</strong> [Field FIELD_UN<br />

GregorianCalendar.get DEFINED].(Note: 60 only<br />

Second [Method get allowable <strong>for</strong> leap<br />

Second()] + javax.xml.data second.)javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen type.<strong>XML</strong>GregorianCalen<br />

dar.getFractionalSecond dar.getMillisecond [Method<br />

[Method getFraction getMillisecond()] allows<br />

alSecond()]<br />

only <strong>for</strong> millisecond preci<br />

sion, is optional and has a<br />

value of javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED] when it is un<br />

defined.javax.xml.data<br />

type.<strong>XML</strong>GregorianCalen<br />

dar.getFractionalSecond<br />

[Method getFraction<br />

alSecond()] allows <strong>for</strong> infin<br />

ite precision over the range<br />

from 0.0 to 1.0.Fraction<br />

alSecond is optional and<br />

has a value of null when it<br />

is undefined.<br />

timezone<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar.get<br />

Timezone [Method get<br />

Timezone()]<br />

Number of minutes or<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalen<br />

dar.FIELD_UNDEFINED<br />

[Field FIELD_UN<br />

DEFINED]. Value range<br />

from -14 hours (-14 * 60<br />

minutes) to 14 hours (14 *<br />

60 minutes) exclusive.<br />

All maximum value space constraints listed <strong>for</strong> the fields in the table above are checked by factory methods, setter<br />

methods and parse methods of this class. IllegalArgumentException is thrown when parameter's value is<br />

outside the maximum value constraint <strong>for</strong> the field. Validation checks, <strong>for</strong> example, whether days in month should be<br />

208


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Synopsis<br />

limited to 29, 30 or 31 days, that are dependent on the values of other fields are not checked by these methods. The<br />

following operations are defined <strong>for</strong> this class:<br />

• factory methods to create instances<br />

• accessors/mutators <strong>for</strong> independent date/time fields<br />

• conversion between this class and W3C <strong>XML</strong> Schema 1.0 lexical representation<br />

• conversion between this class and java.util.GregorianCalendar<br />

• partial order relation comparator method, javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [ Method com<br />

pare(javax.xml.datatype.<strong>XML</strong>GregorianCalendar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

• javax.xml.datatype.<strong>XML</strong>GregorianCalendar.equals [ Method equals(java.lang.Object)] defined relative to<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [ Method compare(javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)].<br />

• addition operation with javax.xml.datatype.Duration [ Class Duration]. instance as defined in W3C <strong>XML</strong> Schema<br />

1.0 Part 2, Appendix E, Adding durations to dateTimes<br />

[http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes].<br />

public <strong>XML</strong>GregorianCalendarimplements Serializable, Cloneable {<br />

public <strong>XML</strong>GregorianCalendar();<br />

static <strong>XML</strong>GregorianCalendar createDateTime(java.math.BigInteger year,<br />

int month,<br />

int day,<br />

int hours,<br />

int minutes,<br />

int seconds,<br />

java.math.BigDecimal fractionalSecond,<br />

int timezone);<br />

static <strong>XML</strong>GregorianCalendar createDateTime(int year,<br />

int month,<br />

int day,<br />

int hour,<br />

int minute,<br />

int second);<br />

static <strong>XML</strong>GregorianCalendar createDateTime(int year,<br />

int month,<br />

int day,<br />

int hours,<br />

int minutes,<br />

int seconds,<br />

int milliseconds,<br />

int timezone);<br />

static <strong>XML</strong>GregorianCalendar createDate(int year,<br />

int month,<br />

209


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

int day,<br />

int timezone);<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

int timezone);<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

java.math.BigDecimal fractionalSecond,<br />

int timezone);<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

int milliseconds,<br />

int timezone);<br />

public BigInteger getEon();<br />

public int getYear();<br />

public BigInteger getEonAndYear();<br />

public int getMonth();<br />

public int getDay();<br />

public int getTimezone();<br />

public int getHour();<br />

public int getMinute();<br />

public int getSecond();<br />

public int getMillisecond();<br />

public BigDecimal getFractionalSecond();<br />

public void setYear(java.math.BigInteger year);<br />

public void setYear(int year);<br />

public void setMonth(int month);<br />

public void setDay(int day);<br />

public void setTimezone(int offset);<br />

public void setTime(int hour,<br />

int minute,<br />

int second);<br />

210


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

public void setTime(int hour,<br />

int minute,<br />

int second,<br />

java.math.BigDecimal fractional);<br />

public void setTime(int hour,<br />

int minute,<br />

int second,<br />

int millisecond);<br />

static int compare(javax.xml.datatype.<strong>XML</strong>GregorianCalendar lhs,<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar rhs);<br />

public boolean equals(java.lang.Object obj);<br />

public int hashCode();<br />

static <strong>XML</strong>GregorianCalendar parse(java.lang.String lexicalRepresentation);<br />

public String to<strong>XML</strong>Format();<br />

public QName get<strong>XML</strong>SchemaType();<br />

public boolean isValid();<br />

public void add(javax.xml.datatype.Duration duration);<br />

public GregorianCalendar toGregorianCalendar();<br />

public GregorianCalendar toGregorianCalendar(java.util.TimeZone timezone,<br />

java.util.Locale aLocale,<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar defa<br />

static <strong>XML</strong>GregorianCalendar fromGregorianCalendar(java.util.GregorianCalendar cal);<br />

public Object clone();<br />

public void clear();<br />

}<br />

Author Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi@Sun.com], Joseph Fialli<br />

[mailto:Joseph.Fialli@Sun.com]<br />

Version $Revision: 1.16 $, $Date: 2003/12/11 21:01:20 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

javax.xml.datatype.Duration [Class Duration]<br />

java.lang.Object<br />

|<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar<br />

211


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Members<br />

Constructor <strong>XML</strong>GregorianCalendar()<br />

Field APRIL<br />

public <strong>XML</strong>GregorianCalendar();<br />

Create an instance with all date/time datatype fields set to javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UN<br />

DEFINED [ Field FIELD_UNDEFINED] or null respectively.<br />

static int APRIL ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> fourth month of year.<br />

Field AUGUST<br />

static int AUGUST ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field DATE<br />

Value <strong>for</strong> eighth month of year.<br />

static javax.xml.namespace.QName DATE ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype date.<br />

Field DATETIME<br />

static javax.xml.namespace.QName DATETIME ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype dateTime.<br />

Field DECEMBER<br />

static int DECEMBER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field EQUAL<br />

Value <strong>for</strong> twelve month of year.<br />

static int EQUAL ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [Method compare(javax.xml.datatype.XM<br />

LGregorianCalendar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

212


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Partial order relation comparison result.<br />

Field FEBRUARY<br />

static int FEBRUARY ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> second month of year.<br />

Field FIELD_UNDEFINED<br />

Field GDAY<br />

static int FIELD_UNDEFINED ;<br />

Designation that an "int" field is not set.<br />

static javax.xml.namespace.QName GDAY ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype gDay.<br />

Field GMONTH<br />

static javax.xml.namespace.QName GMONTH ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype gMonth.<br />

Field GMONTHDAY<br />

static javax.xml.namespace.QName GMONTHDAY ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype gMonthDay.<br />

Field GREATER<br />

static int GREATER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [Method compare(javax.xml.datatype.XM<br />

LGregorianCalendar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

Field GYEAR<br />

Partial order relation comparison result.<br />

static javax.xml.namespace.QName GYEAR ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype gYear.<br />

Field GYEARMONTH<br />

static javax.xml.namespace.QName GYEARMONTH ;<br />

213


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype gYearMonth.<br />

Field INDETERMINATE<br />

static int INDETERMINATE ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [Method compare(javax.xml.datatype.XM<br />

LGregorianCalendar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

Partial order relation comparison result.<br />

Field JANUARY<br />

static int JANUARY ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field JULY<br />

Value <strong>for</strong> first month of year.<br />

static int JULY ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field JUNE<br />

Value <strong>for</strong> seventh month of year.<br />

static int JUNE ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> sixth month of year.<br />

Field LEAP_YEAR_DEFAULT<br />

static javax.xml.datatype.<strong>XML</strong>GregorianCalendar LEAP_YEAR_DEFAULT ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.toGregorianCalendar [Method toGregorianCalen<br />

dar(java.util.TimeZone, java.util.Locale, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

Use as a template <strong>for</strong> default field values when converting to a java.util.GregorianCalendar, set to a leap<br />

year date of January 1, 0400 at midnight.<br />

Field LESSER<br />

static int LESSER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.compare [Method compare(javax.xml.datatype.XM<br />

LGregorianCalendar, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

214


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Field MARCH<br />

Partial order relation comparison result.<br />

static int MARCH ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field MAY<br />

Value <strong>for</strong> third month of year.<br />

static int MAY ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> fifth month of year.<br />

Field NOVEMBER<br />

static int NOVEMBER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> eleven month of year.<br />

Field OCTOBER<br />

static int OCTOBER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Value <strong>for</strong> tenth month of year.<br />

Field SEPTEMBER<br />

static int SEPTEMBER ;<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getMonth [Method getMonth()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setMonth [Method setMonth(int)]<br />

Field TIME<br />

Value <strong>for</strong> ninth month of year.<br />

static javax.xml.namespace.QName TIME ;<br />

Fully qualified name <strong>for</strong> W3C <strong>XML</strong> Schema 1.0 datatype time.<br />

215


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method add(Duration)<br />

public void add(javax.xml.datatype.Duration duration);<br />

Parameters<br />

duration<br />

Duration to add to this <strong>XML</strong>GregorianCalendar.<br />

Exceptions<br />

NullPointerException<br />

when duration parameter is null.<br />

Add duration to this instance.<br />

The computation is specified in <strong>XML</strong> Schema 1.0 Part 2, Appendix E, Adding durations to dateTimes><br />

[http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes]. date/time field mapping table<br />

[#datetimefieldsmapping] defines the mapping from <strong>XML</strong> Schema 1.0 dateTime fields to this class' representation<br />

of those fields.<br />

Method clear()<br />

public void clear();<br />

Unset all fields to undefined.<br />

Set all int fields to javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED]<br />

and reference fields to null.<br />

Method clone()<br />

public Object clone();<br />

Creates and returns a copy of this object.<br />

Method compare(<strong>XML</strong>GregorianCalendar, <strong>XML</strong>GregorianCalendar)<br />

static int compare(javax.xml.datatype.<strong>XML</strong>GregorianCalendar lhs,<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar rhs);<br />

Parameters<br />

lhs<br />

rhs<br />

instance of <strong>XML</strong>GregorianCalendar to compare<br />

instance of <strong>XML</strong>GregorianCalendar to compare<br />

returns the relationship between lhs and rhs as javax.xml.datatype.<strong>XML</strong>GregorianCalendar.LESSER [<br />

Field LESSER], javax.xml.datatype.<strong>XML</strong>GregorianCalendar.EQUAL [ Field EQUAL],<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.GREATER [ Field GREATER] or javax.xml.datatype.XM<br />

LGregorianCalendar.INDETERMINATE [ Field INDETERMINATE].<br />

Exceptions<br />

NullPointerException<br />

if lhs or rhs parameters are null.<br />

216


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Compare two instances of W3C <strong>XML</strong> Schema 1.0 date/time datatypes according to partial order relation defined in<br />

W3C <strong>XML</strong> Schema 1.0 Part 2, Section 3.2.7.3, Order relation on dateTime<br />

[http://www.w3.org/TR/xmlschema-2/#dateTime-order].<br />

xsd:dateTime datatype field mapping to accessors of this class are defined in date/time field mapping table<br />

[#datetimefieldmapping].<br />

Method createDate(int, int, int, int)<br />

static <strong>XML</strong>GregorianCalendar createDate(int year,<br />

int month,<br />

int day,<br />

int timezone);<br />

Parameters<br />

year<br />

month<br />

day<br />

timezone<br />

returns<br />

of <strong>XML</strong>GregorianCalendar to be created.<br />

of <strong>XML</strong>GregorianCalendar to be created.<br />

of <strong>XML</strong>GregorianCalendar to be created.<br />

offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field<br />

FIELD_UNDEFINED] indicates optional field is not set.<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> representation of <strong>XML</strong> Schema builtin datatype date or g*.<br />

For example, an instance of gYear can be created invoking this factory with month and day parameters set to<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED].<br />

Method createDateTime(BigInteger, int, int, int, int, int, BigDecimal, int)<br />

static <strong>XML</strong>GregorianCalendar createDateTime(java.math.BigInteger year,<br />

int month,<br />

int day,<br />

int hours,<br />

int minutes,<br />

int seconds,<br />

java.math.BigDecimal fractionalSecond,<br />

int timezone);<br />

Parameters<br />

year<br />

month<br />

represents both high-order eons and low-order year.<br />

of dateTime<br />

217


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

day<br />

hours<br />

minutes<br />

seconds<br />

fractionalSecond<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

value of null indicates optional field is absent.<br />

timezone offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [<br />

Field FIELD_UNDEFINED] indicates optional field is not set.<br />

returns<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> representation of <strong>XML</strong> Schema builtin datatype dateTime. All possible fields are specified <strong>for</strong> this<br />

factory method.<br />

Method createDateTime(int, int, int, int, int, int)<br />

static <strong>XML</strong>GregorianCalendar createDateTime(int year,<br />

int month,<br />

int day,<br />

int hour,<br />

int minute,<br />

int second);<br />

Parameters<br />

year<br />

month<br />

day<br />

hour<br />

minute<br />

second<br />

returns<br />

represents both high-order eons and low-order year.<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

218


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Create a <strong>Java</strong> instance of <strong>XML</strong> Schema builtin datatype dateTime.<br />

Method createDateTime(int, int, int, int, int, int, int, int)<br />

static <strong>XML</strong>GregorianCalendar createDateTime(int year,<br />

int month,<br />

int day,<br />

int hours,<br />

int minutes,<br />

int seconds,<br />

int milliseconds,<br />

int timezone);<br />

Parameters<br />

year<br />

month<br />

day<br />

hours<br />

minutes<br />

seconds<br />

represents low-order year.<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

of dateTime<br />

milliseconds of dateTime. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [<br />

Field FIELD_UNDEFINED] indicates optional field is not set.<br />

timezone offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [<br />

Field FIELD_UNDEFINED] indicates optional field is not set.<br />

returns<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> representation of <strong>XML</strong> Schema builtin datatype dateTime. All possible fields are specified <strong>for</strong> this<br />

factory method.<br />

Method createTime(int, int, int, BigDecimal, int)<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

java.math.BigDecimal fractionalSecond,<br />

int timezone);<br />

219


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Parameters<br />

hours<br />

minutes<br />

seconds<br />

fractionalSecond<br />

number of hours<br />

number of minutes<br />

number of seconds<br />

value of null indicates that this optional field is not set.<br />

timezone offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [<br />

Field FIELD_UNDEFINED] indicates optional field is not set.<br />

returns<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> instance of <strong>XML</strong> Schema builtin datatype time.<br />

Method createTime(int, int, int, int)<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

int timezone);<br />

Parameters<br />

hours<br />

minutes<br />

seconds<br />

timezone<br />

returns<br />

number of hours<br />

number of minutes<br />

number of seconds<br />

offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field<br />

FIELD_UNDEFINED] indicates optional field is not set.<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> instance of <strong>XML</strong> Schema builtin datatype time.<br />

220


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method createTime(int, int, int, int, int)<br />

static <strong>XML</strong>GregorianCalendar createTime(int hours,<br />

int minutes,<br />

int seconds,<br />

int milliseconds,<br />

int timezone);<br />

Parameters<br />

hours<br />

minutes<br />

seconds<br />

milliseconds<br />

number of hours<br />

number of minutes<br />

number of seconds<br />

number of milliseconds<br />

timezone offset in minutes. javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [<br />

Field FIELD_UNDEFINED] indicates optional field is not set.<br />

returns<br />

<strong>XML</strong>GregorianCalendar created from parameter values.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [Field FIELD_UNDEFINED]<br />

Create a <strong>Java</strong> instance of <strong>XML</strong> Schema builtin datatype time.<br />

Method equals(Object)<br />

public boolean equals(java.lang.Object obj);<br />

Parameters<br />

obj<br />

returns<br />

to compare.<br />

true when compare(this,(<strong>XML</strong>GregorianCalendar)obj) == EQUAL..<br />

Indicates whether parameter obj is "equal to" this one.<br />

Method fromGregorianCalendar(GregorianCalendar)<br />

static <strong>XML</strong>GregorianCalendar fromGregorianCalendar(java.util.GregorianCalendar cal);<br />

Parameters<br />

cal<br />

returns<br />

java.util.GregorianCalendar used to create <strong>XML</strong>GregorianCalendar<br />

<strong>XML</strong>GregorianCalendar created from java.util.GregorianCalendar<br />

Convert a java.util.GregorianCalendar to <strong>XML</strong> Schema 1.0 representation.<br />

221


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Field by Field Conversion from java.util.GregorianCalendar to<br />

this class<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar field<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.setYear [Method setYear(int)]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.setMonth [Method set<br />

Month(int)]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.setDay [Method setDay(int)]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.setTime [Method setTime(int,<br />

int, int, java.math.BigDecimal)]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.setTimezone [Method set<br />

Timezone(int)]*<br />

java.util.GregorianCalen<br />

dar field<br />

ERA == GregorianCalen<br />

dar.BC ? -YEAR : YEAR<br />

MONTH + 1<br />

DAY_OF_MONTH<br />

HOUR_OF_DAY, MINUTE,<br />

SECOND, MILLISECOND<br />

(ZONE_OFFSET + DST_OFFSET)<br />

/ (60*1000)(in minutes)<br />

*conversion loss of in<strong>for</strong>mation. It is not possible to represent a java.util.GregorianCalendar daylight<br />

savings timezone id in the <strong>XML</strong> Schema 1.0 date/time datatype representation.<br />

Method getDay()<br />

public int getDay();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setDay [Method setDay(int)]<br />

Return day in month or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED].<br />

Value constraints <strong>for</strong> this value are summarized in day field of date/time field mapping table [#datetimefield-day].<br />

Method getEon()<br />

public BigInteger getEon();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getYear [Method getYear()], javax.xml.datatype.XM<br />

LGregorianCalendar.getEonAndYear [Method getEonAndYear()]<br />

Get the eons of the year. null if this optional part of the year field is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in year field of date/time field mapping table [#datetimefield-year].<br />

Method getEonAndYear()<br />

public BigInteger getEonAndYear();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getEon [Method getEon()], javax.xml.datatype.XM<br />

LGregorianCalendar.getYear [Method getYear()]<br />

Return <strong>XML</strong> Schema 1.0 dateTime datatype field <strong>for</strong> year.<br />

222


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Value constraints <strong>for</strong> this value are summarized in year field of date/time field mapping table [#datetimefield-year].<br />

Method getFractionalSecond()<br />

public BigDecimal getFractionalSecond();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getSecond [Method getSecond()], javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int, java.math.BigDecimal)]<br />

Return fractional seconds.<br />

null is returned when this optional field is not defined.<br />

Value constraints are detailed in second field of date/time field mapping table [#datetimefield-second].<br />

Method getHour()<br />

public int getHour();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int)]<br />

Return hours or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED].<br />

Returns javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED] if this field<br />

is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in hour field of date/time field mapping table [#datetimefield-hour].<br />

Method getMillisecond()<br />

public int getMillisecond();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getFractionalSecond [Method getFractionalSecond()],<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int)]<br />

Return milliseconds or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED].<br />

Returns javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED] if this field<br />

is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in second field of date/time field mapping table [#datetimefield-second].<br />

Method getMinute()<br />

public int getMinute();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int)]<br />

Return minutes or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED]. Returns javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED] if this field is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in minute field of date/time field mapping table [#datetimefield-minute].<br />

223


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method getMonth()<br />

public int getMonth();<br />

Return number of month or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED].<br />

Value constraints <strong>for</strong> this value are summarized in month field of date/time field mapping table [#datetimefield-month].<br />

Method getSecond()<br />

public int getSecond();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getFractionalSecond [Method getFractionalSecond()],<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int)]<br />

Return seconds or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UN<br />

DEFINED].<br />

Returns javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED] if this field<br />

is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in second field of date/time field mapping table [#datetimefield-second].<br />

Method getTimezone()<br />

public int getTimezone();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTimezone [Method setTimezone(int)]<br />

Return timezone offset in minutes or javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field<br />

FIELD_UNDEFINED] if this optional field is not defined.<br />

Value constraints <strong>for</strong> this value are summarized in timezone field of date/time field mapping table<br />

[#datetimefield-timezone].<br />

Method get<strong>XML</strong>SchemaType()<br />

public QName get<strong>XML</strong>SchemaType();<br />

Exceptions<br />

java.lang.IllegalStateEx<br />

ception<br />

if the combination of set fields does not match one of the eight defined <strong>XML</strong> Schema<br />

builtin date/time datatypes.<br />

Return the name of the <strong>XML</strong> Schema date/time type that this instance maps to. Type is computed based on fields that<br />

are set.<br />

Required fields <strong>for</strong> <strong>XML</strong> Schema 1.0 Date/Time Datatypes.(timezone is optional <strong>for</strong> all date/time datatypes)<br />

Datatype<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.DATE<br />

year<br />

X<br />

month<br />

X<br />

day<br />

X<br />

hour<br />

X<br />

minute<br />

X<br />

second<br />

X<br />

224


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

TIME [Field<br />

DATETIME]<br />

Required fields <strong>for</strong> <strong>XML</strong> Schema 1.0 Date/Time Datatypes.(timezone is optional <strong>for</strong> all date/time datatypes)<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.DATE<br />

[Field DATE]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.TIME<br />

[Field TIME]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.GYEAR<br />

MONTH [Field<br />

GYEAR<br />

MONTH]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.GMONTHDAY<br />

[ F i e l d<br />

GMONTHDAY]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.GYEAR<br />

[Field GYEAR]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.GMONTH<br />

[ F i e l d<br />

GMONTH]<br />

javax.xml.data<br />

type.<strong>XML</strong><br />

GregorianCalen<br />

dar.GDAY<br />

[Field GDAY]<br />

Method getYear()<br />

X<br />

X<br />

X<br />

public int getYear();<br />

X<br />

X<br />

X<br />

X<br />

X<br />

X<br />

X<br />

X<br />

X<br />

X<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.getEon [Method getEon()], javax.xml.datatype.XM<br />

LGregorianCalendar.getEonAndYear [Method getEonAndYear()]<br />

225


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Return low order component <strong>XML</strong> Schema 1.0 dataTime datatype field <strong>for</strong> year or javax.xml.datatype.<strong>XML</strong>Gregori<br />

anCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED].<br />

Value constraints <strong>for</strong> this value are summarized in year field of date/time field mapping table [#datetimefield-year].<br />

Method hashCode()<br />

public int hashCode();<br />

Returns a hash code consistent with the definition of the equals method.<br />

Method isValid()<br />

public boolean isValid();<br />

Validate instance by get<strong>XML</strong>SchemaType() constraints.<br />

Method parse(String)<br />

static <strong>XML</strong>GregorianCalendar parse(java.lang.String lexicalRepresentation);<br />

Parameters<br />

lexicalRepresentation<br />

returns<br />

Lexical representation of one the 8 <strong>XML</strong> Schema calendar datatypes.<br />

<strong>XML</strong>GregorianCalendar created from parsing lexicalRepresentation<br />

parameter.<br />

Exceptions<br />

IllegalArgumentException<br />

NullPointerException<br />

If the given string does not con<strong>for</strong>m to the a<strong>for</strong>ementioned specification.<br />

If the given string is null.<br />

Constructs a new <strong>XML</strong>GregorianCalendar object by parsing its lexical string representation as defined in <strong>XML</strong> Schema<br />

1.0 Part 2, Section 3.2.[7-14].1, Lexical Representation. [http://www.w3.org/TR/xmlschema-2/#dateTime-order]<br />

The string representation may not have any leading and trailing whitespaces.<br />

The parsing is done field by field so that the following holds <strong>for</strong> any lexically correct string x:<br />

new <strong>XML</strong>GregorianCalendar(x).to<strong>XML</strong>Format().equals(x)<br />

Returns a non-null valid <strong>XML</strong>GregorianCalendar object that holds the value indicated by the lexicalRepresentation<br />

parameter.<br />

Method setDay(int)<br />

public void setDay(int day);<br />

226


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Parameters<br />

day<br />

value constraints summarized in day field of date/time field mapping table [#datetimefield-day].<br />

Exceptions<br />

IllegalArgumentException<br />

if day parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

Set days in month.<br />

Unset this field by invoking the setter with a parameter value of javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UN<br />

DEFINED [ Field FIELD_UNDEFINED].<br />

Method setMonth(int)<br />

public void setMonth(int month);<br />

Parameters<br />

month<br />

value constraints summarized in month field of date/time field mapping table [#datetimefield-month].<br />

Exceptions<br />

IllegalArgumentException<br />

if month parameter is outside value constraints <strong>for</strong> the field as specified in date/time<br />

field mapping table [#datetimefieldmapping].<br />

Set month.<br />

Unset this field by invoking the setter with a parameter value of javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UN<br />

DEFINED [ Field FIELD_UNDEFINED].<br />

Method setTime(int, int, int)<br />

public void setTime(int hour,<br />

int minute,<br />

int second);<br />

Parameters<br />

hour<br />

minute<br />

second<br />

value constraints are summarized in hour field of date/time field mapping table [#datetimefield-hour].<br />

value constraints are summarized in minute field of date/time field mapping table [#datetimefield-minute].<br />

value constraints are summarized in second field of date/time field mapping table [#datetimefield-second].<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

See Also javax.xml.datatype.<strong>XML</strong>GregorianCalendar.setTime [Method setTime(int, int, int,<br />

java.math.BigDecimal)]<br />

227


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Set time as one unit.<br />

Method setTime(int, int, int, BigDecimal)<br />

public void setTime(int hour,<br />

int minute,<br />

int second,<br />

java.math.BigDecimal fractional);<br />

Parameters<br />

hour<br />

minute<br />

second<br />

fractional<br />

value constraints are summarized in hour field of date/time field mapping table<br />

[#datetimefield-hour].<br />

value constraints are summarized in minute field of date/time field mapping table<br />

[#datetimefield-minute].<br />

value constraints are summarized in second field of date/time field mapping table<br />

[#datetimefield-second].<br />

value of null indicates this optional field is not set.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

Set time as one unit, including the optional infinite precison fractional seconds.<br />

Method setTime(int, int, int, int)<br />

public void setTime(int hour,<br />

int minute,<br />

int second,<br />

int millisecond);<br />

Parameters<br />

hour<br />

minute<br />

second<br />

millisecond<br />

value constraints are summarized in hour field of date/time field mapping table<br />

[#datetimefield-hour].<br />

value constraints are summarized in minute field of date/time field mapping table<br />

[#datetimefield-minute].<br />

value constraints are summarized in second field of date/time field mapping table<br />

[#datetimefield-second].<br />

value of javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field<br />

FIELD_UNDEFINED] indicates this optional field is not set.<br />

Exceptions<br />

IllegalArgumentException<br />

if any parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

228


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Set time as one unit, including optional milliseconds.<br />

Method setTimezone(int)<br />

public void setTimezone(int offset);<br />

Parameters<br />

offset value constraints summarized in timezone field of date/time field mapping table<br />

[#datetimefield-timezone].<br />

Exceptions<br />

IllegalArgumentException<br />

if offset parameter is outside value constraints <strong>for</strong> the field as specified in date/time<br />

field mapping table [#datetimefieldmapping].<br />

Set the number of minutes in the timezone offset.<br />

Unset this field by invoking the setter with a parameter value of javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UN<br />

DEFINED [ Field FIELD_UNDEFINED].<br />

Method setYear(BigInteger)<br />

public void setYear(java.math.BigInteger year);<br />

Parameters<br />

year<br />

value constraints summarized in year field of date/time field mapping table [#datetimefield-year].<br />

Exceptions<br />

IllegalArgumentException<br />

if year parameter is outside value constraints <strong>for</strong> the field as specified in date/time field<br />

mapping table [#datetimefieldmapping].<br />

Set low and high order component of XSD dateTime year field.<br />

Unset this field by invoking the setter with a parameter value of null.<br />

Method setYear(int)<br />

public void setYear(int year);<br />

Parameters<br />

year<br />

value constraints are summarized in year field of date/time field mapping table [#datetimefield-year]. If year<br />

is javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UNDEFINED [ Field FIELD_UNDEFINED], then<br />

eon is set to null.<br />

Set year of XSD dateTime year field.<br />

Unset this field by invoking the setter with a parameter value of javax.xml.datatype.<strong>XML</strong>GregorianCalendar.FIELD_UN<br />

DEFINED [ Field FIELD_UNDEFINED].<br />

229


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Method toGregorianCalendar()<br />

public GregorianCalendar toGregorianCalendar();<br />

See Also<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar.toGregorianCalendar [Method toGregorianCalen<br />

dar(java.util.TimeZone, java.util.Locale, javax.xml.datatype.<strong>XML</strong>GregorianCalendar)]<br />

Convert this to java.util.GregorianCalendar.<br />

When this instance has an undefined field, this conversion relies on the java.util.GregorianCalendar<br />

default <strong>for</strong> its corresponding field. A notable difference between <strong>XML</strong> Schema 1.0 date/time datatypes and<br />

java.util.GregorianCalendar is that Timezone value is optional <strong>for</strong> date/time datatypes and it is a required<br />

field <strong>for</strong> java.util.GregorianCalendar. See javadoc <strong>for</strong> java.util.TimeZone.getDefault() on<br />

how the default is determined. To explicitly specify the TimeZone instance, see javax.xml.datatype.<strong>XML</strong>Gregorian<br />

Calendar.toGregorianCalendar [ Method toGregorianCalendar(java.util.TimeZone, java.util.Locale, javax.xml.data<br />

type.<strong>XML</strong>GregorianCalendar)].<br />

Field by Field Conversion from this class to java.util.GregorianCal<br />

endar<br />

java.util.GregorianCalen<br />

dar field<br />

ERA<br />

YEAR<br />

MONTH<br />

DAY_OF_MONTH<br />

AM_PM<br />

HOUR_OF_DAY<br />

MINUTE<br />

SECOND<br />

MILLISECOND<br />

javax.xml.datatype.<strong>XML</strong><br />

GregorianCalendar field<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getEonAndYear [Method<br />

getEonAndYear()].signum() < 0<br />

? GregorianCalendar.BC :<br />

GregorianCalendar.AD<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getEonAndYear [Method<br />

getEonAndYear()].abs().int<br />

Value()*<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getMonth [Method getMonth()]<br />

- 1<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getDay [Method getDay()]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getHour [Method getHour()]<<br />

12 : Calendar.AM : Calendar.PM<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getHour [Method getHour()]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getMinute [Method getMinute()]<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getSecond [Method getSecond()]<br />

get millisecond order from<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getFractionalSecond [Method<br />

getFractionalSecond()]*<br />

230


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Field by Field Conversion from this class to java.util.GregorianCal<br />

endar<br />

GregorianCalendar.set<br />

TimeZone(TimeZone)<br />

javax.xml.datatype.<strong>XML</strong>GregorianCal<br />

endar.getTimezone [Method get<br />

Timezone()] <strong>for</strong>matted into Custom<br />

timezone id<br />

* designates possible loss of precision during the conversion due to source datatype having higer precison than target<br />

datatype.<br />

Method toGregorianCalendar(TimeZone, Locale, <strong>XML</strong>GregorianCalendar)<br />

public GregorianCalendar toGregorianCalendar(java.util.TimeZone timezone,<br />

java.util.Locale aLocale,<br />

javax.xml.datatype.<strong>XML</strong>GregorianCalendar defa<br />

Parameters<br />

timezone<br />

aLocale<br />

defaults<br />

returns<br />

provide Timezone. null is a legal value.<br />

provide explicit Locale. Use default GregorianCalendar locale if value is null.<br />

provide default field values to use when corresponding field <strong>for</strong> this instance is FIELD_UN<br />

DEFINED or null. If defaultsis null or a field within the specified defaults is undefined,<br />

just use java.util.GregorianCalendar defaults.<br />

a java.util.GregorianCalendar conversion of this instance.<br />

See Also javax.xml.datatype.<strong>XML</strong>GregorianCalendar.LEAP_YEAR_DEFAULT [Field<br />

LEAP_YEAR_DEFAULT]<br />

Convert this along with provided parameters to java.util.GregorianCalendar instance.<br />

Since <strong>XML</strong> Schema 1.0 date/time datetypes has no concept of timezone ids or daylight savings timezone ids, this<br />

conversion operation allows the user to explicitly specify one with timezone parameter.<br />

To compute the return value's TimeZone field,<br />

• when parameter timeZone is non-null, it is the timezone field.<br />

• else when this.getTimezone() != FIELD_UNDECLARED, create a java.util.TimeZone with a<br />

custom timezone id using the this.getTimezone().<br />

• else when defaults.getTimezone() != FIELD_UNDECLARED, create a java.util.TimeZone with<br />

a custom timezone id using defaults.getTimezone().<br />

• else use the GregorianCalendar default timezone value <strong>for</strong> the host is definedas specified by<br />

java.util.TimeZone.getDefault().<br />

Method to<strong>XML</strong>Format()<br />

public String to<strong>XML</strong>Format();<br />

231


Community Draft<br />

Package javax.xml.datatype<br />

Community Draft<br />

Exceptions<br />

java.lang.IllegalStateEx<br />

ception<br />

if the combination of set fields does not match one of the eight defined <strong>XML</strong> Schema<br />

builtin date/time datatypes.<br />

Return the lexical representation of this instance. The <strong>for</strong>mat is specified in <strong>XML</strong> Schema 1.0 Part 2, Section 3.2.[7-<br />

14].1, Lexical Representation". [http://www.w3.org/TR/xmlschema-2/#dateTime-order]<br />

Specific target lexical representation <strong>for</strong>mat is determined by javax.xml.datatype.<strong>XML</strong>GregorianCalendar.get<strong>XML</strong>S<br />

chemaType [ Method get<strong>XML</strong>SchemaType()].<br />

232


Community Draft<br />

Community Draft<br />

Chapter 17. Package javax.xml<br />

Defines core <strong>XML</strong> constants and functionality from the <strong>XML</strong> specifications.<br />

The following core <strong>XML</strong> standards apply:<br />

• Extensible Markup Language (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11/]<br />

• Extensible Markup Language (<strong>XML</strong>) 1.0 (Second Edition) [http://www.w3.org/TR/REC-xml]<br />

• <strong>XML</strong> 1.0 Second Edition Specification Errata [http://www.w3.org/<strong>XML</strong>/xml-V10-2e-errata]<br />

• Namespaces in <strong>XML</strong> 1.1 [http://www.w3.org/TR/xml-names11/]<br />

• Namespaces in <strong>XML</strong> [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

• Namespaces in <strong>XML</strong> Errata [http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

Class AbstractVersion<br />

Synopsis<br />

AbstractVersion provides version in<strong>for</strong>mation about the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> implementation.<br />

public AbstractVersion {<br />

public AbstractVersion();<br />

public String abstract getImplementationTitle();<br />

public String abstract getImplementationVersion();<br />

public String abstract getImplementationVendor();<br />

public String abstract getImplementationVendorID();<br />

public String abstract getImplementationURL();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.5 $, $Date: 2003/12/06 01:20:45 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

javax.xml.Version [Class Version]<br />

java.lang.Object<br />

|<br />

javax.xml.AbstractVersion<br />

233


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Members<br />

Method getImplementationTitle()<br />

public String abstract getImplementationTitle();<br />

Get implementation title. Returns null if not available/applicable.<br />

Method getImplementationURL()<br />

public String abstract getImplementationURL();<br />

Get implementation URL.<br />

e.g. URL with implementation details. Returns null if not available/applicable.<br />

Method getImplementationVendor()<br />

public String abstract getImplementationVendor();<br />

Get implementation vendor. Returns null if not available/applicable.<br />

Method getImplementationVendorID()<br />

public String abstract getImplementationVendorID();<br />

Get implementation vendor ID. e.g. com.sun Returns null if not available/applicable.<br />

Method getImplementationVersion()<br />

public String abstract getImplementationVersion();<br />

Get implementation version. Returns null if not available/applicable.<br />

Class Secure<strong>Processing</strong><br />

Synopsis<br />

Secure<strong>Processing</strong> is a final class that is used by <strong>XML</strong> processors, both parser and trans<strong>for</strong>mer Factories, to<br />

allow <strong>for</strong> secure processing of <strong>XML</strong>.<br />

Exploits are related to the <strong>XML</strong> processessing model and are not implementation specfic. Preventing known exploits<br />

include:<br />

• setting the maximum entity expansion limit<br />

• setting the maximum occurances <strong>for</strong> an Element in a W3C <strong>XML</strong> Schema declarations<br />

• setting the regexp limits <strong>for</strong> W3C <strong>XML</strong> Schema declarations<br />

• preventing the execution of arbitrary functions in a trans<strong>for</strong>mation<br />

final Secure<strong>Processing</strong> {<br />

234


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

public Secure<strong>Processing</strong>();<br />

public Secure<strong>Processing</strong>(int entityExpansionLimit,<br />

int maxOccurNodeLimit);<br />

public void setEntityExpansionLimit(int limit);<br />

public int getEntityExpansionLimit();<br />

public void setMaxOccurNodeLimit(int limit);<br />

public int getMaxOccurNodeLimit();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com], Rajiv Mordani [mailto:Rajiv.Mordani@Sun.com]<br />

Version $Revision: 1.10 $, $Date: 2003/12/06 01:20:45 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.Secure<strong>Processing</strong><br />

Members<br />

Constructor Secure<strong>Processing</strong>()<br />

public Secure<strong>Processing</strong>();<br />

Default constructor that sets reasonable maximum processing values using javax.xml.Secure<strong>Processing</strong>.DEAFULT_EN<br />

TITY_EXPANSION_LIMIT [ Field DEAFULT_ENTITY_EXPANSION_LIMIT] and javax.xml.SecurePro<br />

cessing.DEAFULT_MAXOCCUR_NODE_LIMIT [ Field DEAFULT_MAXOCCUR_NODE_LIMIT].<br />

Constructor Secure<strong>Processing</strong>(int, int)<br />

public Secure<strong>Processing</strong>(int entityExpansionLimit,<br />

int maxOccurNodeLimit);<br />

Parameters<br />

entityExpansionLimit<br />

maxOccurNodeLimit<br />

Maximum extity expansion limit.<br />

Maximum W3C <strong>XML</strong> Schema declaration occurance node limit, maxOccur.<br />

Constructor that explicitly sets maximum processing values.<br />

Field DEAFULT_ENTITY_EXPANSION_LIMIT<br />

static int DEAFULT_ENTITY_EXPANSION_LIMIT ;<br />

235


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Default maximum entity expansion limit is 100.<br />

Field DEAFULT_MAXOCCUR_NODE_LIMIT<br />

static int DEAFULT_MAXOCCUR_NODE_LIMIT ;<br />

Default maximum W3C <strong>XML</strong> Schema declaration occurance node limit, maxOccur, is 100.<br />

Method getEntityExpansionLimit()<br />

public int getEntityExpansionLimit();<br />

Get the maximum entity expansion limit.<br />

Method getMaxOccurNodeLimit()<br />

public int getMaxOccurNodeLimit();<br />

Get the maximum W3C <strong>XML</strong> Schema declaration occurance node limit, maxOccur.<br />

Method setEntityExpansionLimit(int)<br />

public void setEntityExpansionLimit(int limit);<br />

Parameters<br />

limit<br />

Maximum entity expansion limit.<br />

Set the maximum entity expansion limit.<br />

An IllegalArgumentException will be thrown if the limit is < 1.<br />

Method setMaxOccurNodeLimit(int)<br />

public void setMaxOccurNodeLimit(int limit);<br />

Parameters<br />

limit<br />

Maximum W3C <strong>XML</strong> Schema declaration occurance node limit, maxOccur.<br />

Set the maximum W3C <strong>XML</strong> Schema declaration occurance node limit, maxOccur.<br />

An IllegalArgumentException will be thrown if the limit is < 1.<br />

Class Version<br />

Provides version in<strong>for</strong>mation about the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> specification and implementation.<br />

Specification version in<strong>for</strong>mation is defined by the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> specification.<br />

Implementation version in<strong>for</strong>mation is defined by querying the service provider as defined in META-INF/ser<br />

vices/javax.xml.AbstractVersion. The service provider must extend javax.xml.AbstractVersion.<br />

236


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Synopsis<br />

final Version {<br />

public Version();<br />

static String getSpecificationTitle();<br />

static String getSpecificationVersion();<br />

static String getSpecificationVendor();<br />

static String getExtensionName();<br />

final String getImplementationTitle();<br />

final String getImplementationVersion();<br />

final String getImplementationVendor();<br />

final String getImplementationVendorID();<br />

final String getImplementationURL();<br />

final String toString();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.10 $, $Date: 2003/12/11 20:13:50 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

javax.xml.AbstractVersion [Class AbstractVersion]<br />

java.lang.Object<br />

|<br />

javax.xml.Version<br />

Members<br />

Constructor Version()<br />

public Version();<br />

Constructor uses implementation version in<strong>for</strong>mation service provider to get version in<strong>for</strong>mation.<br />

Method getExtensionName()<br />

static String getExtensionName();<br />

237


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Get extension name. e.g. "javax.xml.datatype, javax.xml.namespace, javax.xml.parsers, javax.xml.trans<strong>for</strong>m,<br />

javax.xml.validation, javax.xml.xpath"<br />

Returned extension name is a unique identifier <strong>for</strong> the extension in the Jar file. By convention, the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong><br />

<strong>Processing</strong> uses a comma separated list of available packages.<br />

Method getImplementationTitle()<br />

final String getImplementationTitle();<br />

Get implementation title.<br />

Returns null if not available/applicable.<br />

Method getImplementationURL()<br />

final String getImplementationURL();<br />

Get implementation URL. e.g. URL with implementation details.<br />

Returns null if not available/applicable.<br />

Method getImplementationVendor()<br />

final String getImplementationVendor();<br />

Get implementation vendor.<br />

Returns null if not available/applicable.<br />

Method getImplementationVendorID()<br />

final String getImplementationVendorID();<br />

Get implementation vendor ID. e.g. com.sun<br />

Returns null if not available/applicable.<br />

Method getImplementationVersion()<br />

final String getImplementationVersion();<br />

Get implementation version.<br />

Returns null if not available/applicable.<br />

Method getSpecificationTitle()<br />

static String getSpecificationTitle();<br />

Get specification title.<br />

Method getSpecificationVendor()<br />

static String getSpecificationVendor();<br />

238


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Get specification vendor.<br />

Method getSpecificationVersion()<br />

static String getSpecificationVersion();<br />

Get specification version.<br />

Method toString()<br />

final String toString();<br />

Return all version in<strong>for</strong>mation as a human readable String. Version in<strong>for</strong>mation includes:<br />

• specification title<br />

• specification version<br />

• specification vendor<br />

• extension name<br />

• implementation title<br />

• implementation version<br />

• implementation vendor<br />

• implementation vendor ID<br />

• implementation URL<br />

This method satisfies the general contract of java.lang.Object.toString.<br />

Class VersionImpl<br />

Synopsis<br />

Provides version in<strong>for</strong>mation about the <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> implementation.<br />

public VersionImpl extends AbstractVersion {<br />

public VersionImpl();<br />

public String getImplementationTitle();<br />

public String getImplementationVersion();<br />

public String getImplementationVendor();<br />

public String getImplementationVendorID();<br />

public String getImplementationURL();<br />

}<br />

239


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.1 $, $Date: 2003/12/10 17:47:47 $<br />

Since 1.5<br />

Inheritance Path<br />

java.lang.Object<br />

|<br />

javax.xml.AbstractVersion<br />

|<br />

javax.xml.VersionImpl<br />

Members<br />

Method getImplementationTitle()<br />

public String getImplementationTitle();<br />

Get implementation title.<br />

Returns null if not available/applicable.<br />

Method getImplementationURL()<br />

public String getImplementationURL();<br />

Get implementation URL. e.g. URL with implementation details.<br />

Returns null if not available/applicable.<br />

Method getImplementationVendor()<br />

public String getImplementationVendor();<br />

Get implementation vendor.<br />

Returns null if not available/applicable.<br />

Method getImplementationVendorID()<br />

public String getImplementationVendorID();<br />

Get implementation vendor ID. e.g. com.sun<br />

Returns null if not available/applicable.<br />

Method getImplementationVersion()<br />

public String getImplementationVersion();<br />

Get implementation version.<br />

240


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Returns null if not available/applicable.<br />

Class <strong>XML</strong>Constants<br />

Synopsis<br />

Utility class to contain basic <strong>XML</strong> values as constants.<br />

final <strong>XML</strong>Constants {<br />

public <strong>XML</strong>Constants();<br />

final String toString();<br />

}<br />

Author<br />

Jeff Suttor [mailto:Jeff.Suttor@Sun.com]<br />

Version $Revision: 1.6 $, $Date: 2003/12/06 01:20:45 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

Extensible Markup Language (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11/], Extensible Markup<br />

Language (<strong>XML</strong>) 1.0 (Second Edition) [http://www.w3.org/TR/REC-xml], <strong>XML</strong> 1.0 Second<br />

Edition Specification Errata [http://www.w3.org/<strong>XML</strong>/xml-V10-2e-errata], Namespaces in <strong>XML</strong><br />

1.1 [http://www.w3.org/TR/xml-names11/], Namespaces in <strong>XML</strong><br />

[http://www.w3.org/TR/REC-xml-names], Namespaces in <strong>XML</strong> Errata<br />

[http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata], <strong>XML</strong> Schema Part 1: Structures<br />

[http://www.w3.org/TR/xmlschema-1/]<br />

java.lang.Object<br />

|<br />

javax.xml.<strong>XML</strong>Constants<br />

Members<br />

Constructor <strong>XML</strong>Constants()<br />

public <strong>XML</strong>Constants();<br />

<strong>XML</strong>Constants is final and only includes static final values. A constructor is needed to allow<br />

javax.xml.<strong>XML</strong>Constants.toString [ Method toString()] to be invoked.<br />

Field DEFAULT_NS_PREFIX<br />

static java.lang.String DEFAULT_NS_PREFIX ;<br />

See Also<br />

Namespaces in <strong>XML</strong>, 3. Qualified Names [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

Prefix to use to represent the default <strong>XML</strong> Namespace.<br />

241


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Defined by the <strong>XML</strong> specification to be "".<br />

Field NULL_NS_URI<br />

static java.lang.String NULL_NS_URI ;<br />

See Also Namespaces in <strong>XML</strong>, 5.2 Namespace Defaulting<br />

[http://www.w3.org/TR/REC-xml-names/#defaulting]<br />

Namespace URI to use to represent that there is no Namespace.<br />

Defined by the Namespace specification to be "".<br />

Field W3C_<strong>XML</strong>_SCHEMA_INSTANCE_NS_URI<br />

static java.lang.String W3C_<strong>XML</strong>_SCHEMA_INSTANCE_NS_URI ;<br />

See Also<br />

<strong>XML</strong> Schema Part 1: Structures, 2.6 Schema-Related Markup in Documents Being Validated<br />

[http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions]<br />

W3C <strong>XML</strong> Schema Instance Namespace URI.<br />

Defined to be " http://www.w3.org/2001/<strong>XML</strong>Schema-instance".<br />

Field W3C_<strong>XML</strong>_SCHEMA_NS_URI<br />

static java.lang.String W3C_<strong>XML</strong>_SCHEMA_NS_URI ;<br />

See Also<br />

<strong>XML</strong> Schema Part 1: Structures, 2.6 Schema-Related Markup in Documents Being Validated<br />

[http://www.w3.org/TR/xmlschema-1/#Instance_Document_Constructions]<br />

W3C <strong>XML</strong> Schema Namespace URI.<br />

Defined to be " http://www.w3.org/2001/<strong>XML</strong>Schema".<br />

Field <strong>XML</strong>_DTD_NS_URI<br />

static java.lang.String <strong>XML</strong>_DTD_NS_URI ;<br />

<strong>XML</strong> Document Type Declaration Namespace URI as an arbitrary value.<br />

Since not <strong>for</strong>mally defined by any existing standard, arbitrarily define to be " http://www.w3.org/TR/RECxml".<br />

Field <strong>XML</strong>_NS_PREFIX<br />

static java.lang.String <strong>XML</strong>_NS_PREFIX ;<br />

See Also<br />

Namespaces in <strong>XML</strong>, 3. Qualified Names< [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

The official <strong>XML</strong> Namespace prefix.<br />

Defined by the <strong>XML</strong> specification to be " xml".<br />

242


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Field <strong>XML</strong>_NS_URI<br />

static java.lang.String <strong>XML</strong>_NS_URI ;<br />

See Also<br />

Namespaces in <strong>XML</strong>, 3. Qualified Names [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

The official <strong>XML</strong> Namespace name URI.<br />

Defined by the <strong>XML</strong> specification to be " http://www.w3.org/<strong>XML</strong>/1998/namespace".<br />

Field <strong>XML</strong>NS_ATTRIBUTE<br />

static java.lang.String <strong>XML</strong>NS_ATTRIBUTE ;<br />

See Also<br />

Namespaces in <strong>XML</strong>, 3. Qualified Names [http://www.w3.org/TR/REC-xml-names/#ns-qualnames]<br />

The official <strong>XML</strong> attribute used <strong>for</strong> specifying <strong>XML</strong> Namespace declarations.<br />

It is NOT valid to use as a prefix. Defined by the <strong>XML</strong> specification to be " xmlns".<br />

Field <strong>XML</strong>NS_ATTRIBUTE_NS_URI<br />

static java.lang.String <strong>XML</strong>NS_ATTRIBUTE_NS_URI ;<br />

See Also<br />

Namespaces in <strong>XML</strong>, 3. Qualified Names [http://www.w3.org/TR/REC-xml-names/#ns-qualnames],<br />

Namespaces in <strong>XML</strong> Errata [http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata/]<br />

The official <strong>XML</strong> attribute used <strong>for</strong> specifying <strong>XML</strong> Namespace declarations, <strong>XML</strong>Constants.<strong>XML</strong>NS_ATTRIBUTE<br />

[ Field <strong>XML</strong>NS_ATTRIBUTE], Namespace name URI.<br />

Defined by the <strong>XML</strong> specification to be " http://www.w3.org/2000/xmlns/".<br />

Method toString()<br />

final String toString();<br />

Human readable String of all <strong>XML</strong>Constants public fields.<br />

This method satisfies the general contract of java.lang.Object.toString.<br />

Class <strong>XML</strong>Utils<br />

Synopsis<br />

<strong>XML</strong>Utils provides core <strong>XML</strong> utilities.<br />

}<br />

final <strong>XML</strong>Utils {<br />

static boolean isValidNCName(java.lang.String ncName);<br />

static boolean isValidNCName(java.lang.String ncName,<br />

java.lang.String xmlVersion);<br />

243


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

Author Jeff Suttor [mailto:Jeff.Suttor@Sun.com], Kohsuke Kawaguchi<br />

[mailto:kohsuke.kawaguchi@Sun.com]<br />

Version $Revision: 1.9 $, $Date: 2003/12/06 01:20:45 $<br />

Since 1.5<br />

See Also<br />

Inheritance Path<br />

Extensible Markup Language (<strong>XML</strong>) 1.1 [http://www.w3.org/TR/xml11/], Extensible Markup<br />

Language (<strong>XML</strong>) 1.0 (Second Edition) [http://www.w3.org/TR/REC-xml], <strong>XML</strong> 1.0 Second<br />

Edition Specification Errata [http://www.w3.org/<strong>XML</strong>/xml-V10-2e-errata], Namespaces in <strong>XML</strong><br />

1.1, NCName [http://www.w3.org/TR/xml-names11/#NT-NCName], Namespaces in <strong>XML</strong>, NC<br />

Name [http://www.w3.org/TR/REC-xml-names/#NT-NCName], Namespaces in <strong>XML</strong> Errata, 6<br />

December 2002 [http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

java.lang.Object<br />

|<br />

javax.xml.<strong>XML</strong>Utils<br />

Members<br />

Method isValidNCName(String)<br />

static boolean isValidNCName(java.lang.String ncName);<br />

Parameters<br />

ncName<br />

returns<br />

NCName to validate<br />

true if NCName is valid, otherwise false<br />

Exceptions<br />

java.lang.NullPointerEx<br />

ception<br />

if the String being passed in as the parameter is null.<br />

See Also<br />

Namespaces in <strong>XML</strong> 1.1, NCName [http://www.w3.org/TR/xml-names11/#NT-NCName]<br />

Test NCName <strong>for</strong> validity using <strong>XML</strong> 1.1 validity rules.<br />

An NCName of null is invalid and a NullPointerException will be thrown. An NCName of "" is invalid and<br />

false will be returned.<br />

Method isValidNCName(String, String)<br />

static boolean isValidNCName(java.lang.String ncName,<br />

java.lang.String xmlVersion);<br />

Parameters<br />

ncName<br />

xmlVersion<br />

NCName to validate<br />

to validate NCName against<br />

244


Community Draft<br />

Package javax.xml<br />

Community Draft<br />

returns<br />

true if NCName is valid, otherwise false<br />

See Also<br />

Namespaces in <strong>XML</strong> 1.1, NCName [http://www.w3.org/TR/xml-names11/#NT-NCName],<br />

Namespaces in <strong>XML</strong>, NCName [http://www.w3.org/TR/REC-xml-names/#NT-NCName],<br />

Namespaces in <strong>XML</strong> Errata, 6 December 2002<br />

[http://www.w3.org/<strong>XML</strong>/xml-names-19990114-errata]<br />

Test NCName <strong>for</strong> validity using specified version of <strong>XML</strong> validity rules.<br />

An NCName of null is invalid and a NullPointerException will be thrown. An NCName of "" is invalid and<br />

false will be returned.<br />

<strong>XML</strong> versions of "1.0" and "1.1" are supported. An <strong>XML</strong> version of null is invalid and a NullPointerException<br />

will be thrown. Specifying any other value <strong>for</strong> <strong>XML</strong> version will cause an IllegalArgumentException to be<br />

thrown.<br />

245


Community Draft<br />

Community Draft<br />

Chapter 18. Change History<br />

This section lists the changes that have occurred over the development of this specification.<br />

From 1.1 final release to 1.2 final release<br />

Introduced properties to enable validation against xml schemas.<br />

From 1.1 Proposed Final Draft to 1.1 Final Release<br />

Made getLexicalHandler and setLexicalHandler in javax.xml.trans<strong>for</strong>m.sax.SAXResult public methods.<br />

Explicitly spelled out the location of the jaxp.properties to be in the jre/lib directory.<br />

From 1.1 Public Review 2 to Proposed Final Draft<br />

Added getDOMImplementation method to DocumentBuilder.<br />

Added SourceLocator to Trans<strong>for</strong>merConfigurationException.<br />

Added extends DTDHandler to javax.xml.trans<strong>for</strong>m.sax.Trans<strong>for</strong>merHandler<br />

Changed return type of getException in Trans<strong>for</strong>merException to return Throwable.<br />

Renamed TFactoryConfigurationError to Trans<strong>for</strong>merFactoryConfigurationError.<br />

From 1.1 Public Review 1 to 1.1 Public Review 2<br />

Modified javax.xml.trans<strong>for</strong>m to include a new set of <strong>API</strong>s <strong>for</strong> trans<strong>for</strong>mation.<br />

Changed endorsed specifications section to include the second edition of the <strong>XML</strong> 1.0 recommendation, the DOM<br />

Level2 core recommendation and the final version of SAX2-extensions.<br />

From 1.0 Final Release to 1.1 Public Review<br />

Added parameter systemId to all the parse and trans<strong>for</strong>m methods which take Streams as parameters. This was done<br />

to provide a base to resolve relative URIs.<br />

Added setIgnoreWhitespace, setExpandEntityReference, setIgnoringComments, setAttributes and the corresponding<br />

getters to DocumentBuilderFactory.<br />

Added get/setAttribute to Trans<strong>for</strong>mFactory.<br />

Added setEntityResolver, setErrorHandler and get/setXSLParam to Trans<strong>for</strong>m.<br />

Added get/setFeature to SAXParserFactory.<br />

Added get/setProperty to SAXParser.<br />

Added SAX2 extensions.<br />

246


Community Draft<br />

Change History<br />

Community Draft<br />

Added Trans<strong>for</strong>mations<br />

Added more mechanisms to look up an implementation of the various factories.<br />

Removed con<strong>for</strong>mance requirements from the specification and just refer to the con<strong>for</strong>mance requirements as required<br />

by the specifications included by reference.<br />

From 1.0 Public Release to 1.0 Final Release<br />

The reservation of the java and javax namespace prefixes was removed. The <strong>XML</strong> Namespace specification is clear<br />

that a namespace is a collection of names that is identified by a URI reference. The prefix is a local identifier <strong>for</strong> the<br />

URI reference, there<strong>for</strong>e the reservation of the java and javax namespaces was in error.<br />

From 1.0 Public Review to 1.0 Public Release<br />

From the Public Review draft of this specification to the Public Release version, the specification was reordered and<br />

rewritten to address general feedback from the user community. This feedback indicated that the specification was too<br />

detailed in describing the endorsed specifications and not detailed enough in describing the plugability layer.<br />

The newParser method of the SAXParserFactory abstract class was removed. Feedback showed that it was<br />

confusing to be able to obtain both the SAXParser wrapper and the underlying implementation from the factory.<br />

Removing this method allows the <strong>API</strong> to be more understandable while preserving the ability to access the underlying<br />

parser via the getParser method of the SAXParser abstract class.<br />

The getLocale and setLocale methods of the various classes were removed. Instead it was felt that parser im<br />

plementation authors should report errors in the configured default locale of the execution environment.<br />

A new exception named ParserConfigurationException was added so that a parser factory can signal to an<br />

application that it can’t provide a parser with the desired configuration. The checkXXX methods aren’t sufficient <strong>for</strong><br />

this purpose as a situation may arise where there is a mutually exclusive setting of various parser properties. At this<br />

time, this problem is potentially minor as there are only two settable properties on each of the parser types, but in the<br />

future as the number of settable properties increases, the problem would get harder to solve without an exception that<br />

could be thrown at parser creation time. As part of this change, the setXXX property methods of the factories no<br />

longer throw an IllegalArgumentException if they are set to a property which cannot be supported.<br />

The FactoryException class was renamed to FactoryConfigurationError. This rename was undertaken<br />

to emphasize that such an error condition is a fatal condition that an application should not be reasonable expected to<br />

handle.<br />

247


Community Draft<br />

Community Draft<br />

Appendix A. Change Log<br />

Change Log: Community Draft released<br />

: version 0.1 released to the <strong>Java</strong> Community <strong>for</strong> Community Review<br />

: 2003-08-15 00:00 PDT, Jeff Suttor<br />

Change Log: javax.xml.parsers.FactoryFinder class restored, changes to javax.xml.parsers.DocumentBuilderFactory,<br />

javax.xml.parsers.SAXParserFactory, javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>merFactory, javax.xml.trans<strong>for</strong>m.FactoryFinder<br />

classes to use FactoryFinder<br />

: javax.xml source code was originally seeded from a repository that did not contain FactoryFinder<br />

: 2003-08-21 14:00 PDT, Jeff Suttor via Reference Implementation team<br />

Change Log: new methods javax.xml.parsers.DocumentBuilderFactory.setXIncludeAware(boolean state) ,<br />

javax.xml.parsers.DocumentBuilderFactory.isXIncludeAware() , javax.xml.parsers.DocumentBuilder.isXIncludeAware()<br />

, javax.xml.parsers.SAXParserFactory.setXIncludeAware(boolean state) , javax.xml.parsers.SAXParserFactory.isXIn<br />

cludeAware() , javax.xml.parsers.SAXParser.isXIncludeAware()<br />

: need to be able to enable/disable/query XInclude processing state<br />

: 2003-08-28 22:15 PDT, Jeff Suttor via Reference Implementation team<br />

Change Log: new method javax.xml.trans<strong>for</strong>m.setParameters(Properties params), new method javax.xml.trans<strong>for</strong>m.get<br />

Parameters()<br />

: ability to set multiple parameters, get all parameters<br />

: 2003-09-08 00:40 PDT, Jeff Suttor via Ilene Seelemann<br />

Change Log: Community Draft released<br />

: version 0.2 released to the <strong>Java</strong> Community <strong>for</strong> Community Review balloting<br />

: 2003-09-09 00:00 PDT, Jeff Suttor<br />

Change Log: bug: Trans<strong>for</strong>merException.printStackTrace(PrintStream) doesn’t print anything<br />

: PrintStream is now .flush()’d<br />

: 2003-09-09 18:38 PDT, Jeff Suttor<br />

Change Log: editorial: javax.xml.trans<strong>for</strong>mer.ErrorListener specification of behavior when application doesn’t register<br />

its own ErrorListener<br />

: javax.xml.trans<strong>for</strong>m package <strong>Java</strong>doc and javax.xml.trans<strong>for</strong>m.ErrorListener class <strong>Java</strong>doc updated to clarify beha<br />

vior of default ErrorListener<br />

: 2003-09-19 03:06 PDT, Jeff Suttor<br />

Change Log: editorial: SAX Plugability in specification and SAXParserFactory.newInstance() <strong>Java</strong>doc, DOM<br />

Plugability in specification and DocumentBuilderFactory.newInstance() <strong>Java</strong>doc, XSLT Plugability in specification<br />

and Trans<strong>for</strong>merFactory.newInstance() <strong>Java</strong>doc reading of jaxp.properties clarified<br />

: specification prose and <strong>Java</strong>doc updated to include: The jaxp.properties file is read only once by the <strong>JSR</strong> <strong>206</strong> <strong>Java</strong><br />

<strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> implementation and it’s values are then cached <strong>for</strong> future use. If the file does not<br />

exist when the first attempt is made to read from it, no further attempts are made to check <strong>for</strong> its existence. It is not<br />

possible to change the value of any property in jaxp.properties after it has been read <strong>for</strong> the first time.<br />

: 2003-09-24 06:32 PDT, Jeff Suttor<br />

Change Log: functional: Version in specification and class javax.xml.Version and class javax.xml.AbstractVersion<br />

created<br />

: a way to get <strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> specification and implementation version in<strong>for</strong>m<br />

ation is now provided<br />

: 2003-10-15 23:22 PDT, Jeff Suttor<br />

Change Log: documentation: updated <strong>Java</strong>doc in javax.xml.trans<strong>for</strong>m.Trans<strong>for</strong>mer.trans<strong>for</strong>m(Source, Result) ,<br />

javax.xml.trans<strong>for</strong>m.sax.SAXSource.SAXSource() , javax.xml.trans<strong>for</strong>m.dom.DOMSource.DOMSource() ,<br />

javax.xml.trans<strong>for</strong>m.stream.StreamSource.StreamSource()<br />

: clarified that an empty Source is always trans<strong>for</strong>med into an empty Result<br />

: 2003-10-21 20:54 PDT, Jeff Suttor<br />

248


Community Draft<br />

Community Draft<br />

Chapter 19. Colophon<br />

Talk the Talk, Walk the Walk<br />

<strong>JSR</strong> <strong>206</strong> <strong>Java</strong> <strong>API</strong> <strong>for</strong> <strong>XML</strong> <strong>Processing</strong> (<strong>JAXP</strong>) <strong>1.3</strong> was authored in <strong>XML</strong> using the DocBook [http://docbook.org/]<br />

DTD.<br />

The <strong>XML</strong> was trans<strong>for</strong>med into XHTML, HTML and XSL Formatting Objects using the DocBook style sheets. The<br />

XSL Formatting Objects were then trans<strong>for</strong>med into PDF.<br />

Table 19.1. <strong>XML</strong> Usage Conventions<br />

<br />

<br />

"external-spec" is the type of all ulinks that refer to external<br />

specifications<br />

"organization" is the type of all ulinks that refer to organ<br />

izations<br />

249

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!