Path: blob/master/src/java.xml/share/classes/org/xml/sax/package-info.java
40948 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* Provides the interfaces for the Simple API for XML (SAX). Supports both27* the SAX1 and SAX2 APIs.28*29* <h2> SAX2 Standard Feature Flags </h2>30*31* <p>32* One of the essential characteristics of SAX2 is that it added33* feature flags which can be used to examine and perhaps modify34* parser modes, in particular modes such as validation.35* Since features are identified by (absolute) URIs, anyone36* can define such features.37* Currently defined standard feature URIs have the prefix38* <code>http://xml.org/sax/features/</code> before an identifier such as39* <code>validation</code>. Turn features on or off using40* <em>setFeature</em>. Those standard identifiers are:41*42*43* <table class="striped">44* <caption>Standard Features</caption>45* <thead>46* <tr>47* <th scope="col">Feature ID</th>48* <th scope="col">Access</th>49* <th scope="col">Default</th>50* <th scope="col">Description</th>51* </tr>52* </thead>53*54* <tbody>55* <tr>56* <th scope="row">external-general-entities</th>57* <td><em>read/write</em></td>58* <td><em>unspecified</em></td>59* <td> Reports whether this parser processes external60* general entities; always true if validating.61* </td>62* </tr>63*64* <tr>65* <th scope="row">external-parameter-entities</th>66* <td><em>read/write</em></td>67* <td><em>unspecified</em></td>68* <td> Reports whether this parser processes external69* parameter entities; always true if validating.70* </td>71* </tr>72*73* <tr>74* <th scope="row">is-standalone</th>75* <td>(parsing) <em>read-only</em>, (not parsing) <em>none</em></td>76* <td>not applicable</td>77* <td> May be examined only during a parse, after the78* <em>startDocument()</em> callback has been completed; read-only.79* The value is true if the document specified standalone="yes" in80* its XML declaration, and otherwise is false.81* </td>82* </tr>83*84* <tr>85* <th scope="row">lexical-handler/parameter-entities</th>86* <td><em>read/write</em></td>87* <td><em>unspecified</em></td>88* <td> A value of "true" indicates that the LexicalHandler will report89* the beginning and end of parameter entities.90* </td>91* </tr>92*93* <tr>94* <th scope="row">namespaces</th>95* <td><em>read/write</em></td>96* <td>true</td>97* <td> A value of "true" indicates namespace URIs and unprefixed local names98* for element and attribute names will be available.99* </td>100* </tr>101*102* <tr>103* <th scope="row">namespace-prefixes</th>104* <td><em>read/write</em></td>105* <td>false</td>106* <td> A value of "true" indicates that XML qualified names (with prefixes) and107* attributes (including <em>xmlns*</em> attributes) will be available.108* </td>109* </tr>110*111* <tr>112* <th scope="row">resolve-dtd-uris</th>113* <td><em>read/write</em></td>114* <td><em>true</em></td>115* <td> A value of "true" indicates that system IDs in declarations will116* be absolutized (relative to their base URIs) before reporting.117* (That is the default behavior for all SAX2 XML parsers.)118* A value of "false" indicates those IDs will not be absolutized;119* parsers will provide the base URI from120* <em>Locator.getSystemId()</em>.121* This applies to system IDs passed in <ul>122* <li><em>DTDHandler.notationDecl()</em>,123* <li><em>DTDHandler.unparsedEntityDecl()</em>, and124* <li><em>DeclHandler.externalEntityDecl()</em>.125* </ul>126* It does not apply to <em>EntityResolver.resolveEntity()</em>,127* which is not used to report declarations, or to128* <em>LexicalHandler.startDTD()</em>, which already provides129* the non-absolutized URI.130* </td>131* </tr>132*133* <tr>134* <th scope="row">string-interning</th>135* <td><em>read/write</em></td>136* <td><em>unspecified</em></td>137* <td> Has a value of "true" if all XML names (for elements, prefixes,138* attributes, entities, notations, and local names),139* as well as Namespace URIs, will have been interned140* using <em>java.lang.String.intern</em>. This supports fast141* testing of equality/inequality against string constants,142* rather than forcing slower calls to <em>String.equals()</em>.143* </td>144* </tr>145*146* <tr>147* <th scope="row">unicode-normalization-checking</th>148* <td><em>read/write</em></td>149* <td><em>false</em></td>150* <td> Controls whether the parser reports Unicode normalization151* errors as described in section 2.13 and Appendix B of the152* XML 1.1 Recommendation. If true, Unicode normalization153* errors are reported using the ErrorHandler.error() callback.154* Such errors are not fatal in themselves (though, obviously,155* other Unicode-related encoding errors may be).156* </td>157* </tr>158*159* <tr>160* <th scope="row">use-attributes2</th>161* <td><em>read-only</em></td>162* <td>not applicable</td>163* <td> Returns "true" if the <em>Attributes</em> objects passed by164* this parser in <em>ContentHandler.startElement()</em>165* implement the <a href="ext/Attributes2.html"166* ><em>org.xml.sax.ext.Attributes2</em></a> interface.167* That interface exposes additional DTD-related information,168* such as whether the attribute was specified in the169* source text rather than defaulted.170* </td>171* </tr>172*173* <tr>174* <th scope="row">use-locator2</th>175* <td><em>read-only</em></td>176* <td>not applicable</td>177* <td> Returns "true" if the <em>Locator</em> objects passed by178* this parser in <em>ContentHandler.setDocumentLocator()</em>179* implement the <a href="ext/Locator2.html"180* ><em>org.xml.sax.ext.Locator2</em></a> interface.181* That interface exposes additional entity information,182* such as the character encoding and XML version used.183* </td>184* </tr>185*186* <tr>187* <th scope="row">use-entity-resolver2</th>188* <td><em>read/write</em></td>189* <td><em>true</em></td>190* <td> Returns "true" if, when <em>setEntityResolver</em> is given191* an object implementing the <a href="ext/EntityResolver2.html"192* ><em>org.xml.sax.ext.EntityResolver2</em></a> interface,193* those new methods will be used.194* Returns "false" to indicate that those methods will not be used.195* </td>196* </tr>197*198* <tr>199* <th scope="row">validation</th>200* <td><em>read/write</em></td>201* <td><em>unspecified</em></td>202* <td> Controls whether the parser is reporting all validity203* errors; if true, all external entities will be read.204* </td>205* </tr>206*207* <tr>208* <th scope="row">xmlns-uris</th>209* <td><em>read/write</em></td>210* <td><em>false</em></td>211* <td> Controls whether, when the <em>namespace-prefixes</em> feature212* is set, the parser treats namespace declaration attributes as213* being in the <em>http://www.w3.org/2000/xmlns/</em> namespace.214* By default, SAX2 conforms to the original "Namespaces in XML"215* Recommendation, which explicitly states that such attributes are216* not in any namespace.217* Setting this optional flag to "true" makes the SAX2 events conform to218* a later backwards-incompatible revision of that recommendation,219* placing those attributes in a namespace.220* </td>221* </tr>222*223* <tr>224* <th scope="row">xml-1.1</th>225* <td><em>read-only</em></td>226* <td>not applicable</td>227* <td> Returns "true" if the parser supports both XML 1.1 and XML 1.0.228* Returns "false" if the parser supports only XML 1.0.229* </td>230* </tr>231* </tbody>232* </table>233*234* <p>235* Support for the default values of the236* <em>namespaces</em> and <em>namespace-prefixes</em>237* properties is required.238* Support for any other feature flags is entirely optional.239*240*241* <p>242* For default values not specified by SAX2,243* each XMLReader implementation specifies its default,244* or may choose not to expose the feature flag.245* Unless otherwise specified here,246* implementations may support changing current values247* of these standard feature flags, but not while parsing.248*249*250* <h2> SAX2 Standard Handler and Property IDs </h2>251*252* <p>253* For parser interface characteristics that are described254* as objects, a separate namespace is defined. The255* objects in this namespace are again identified by URI, and256* the standard property URIs have the prefix257* <code>http://xml.org/sax/properties/</code> before an identifier such as258* <code>lexical-handler</code> or259* <code>dom-node</code>. Manage those properties using260* <em>setProperty()</em>. Those identifiers are:261*262* <table class="striped">263* <caption>Standard Property IDs</caption>264* <thead>265* <tr>266* <th scope="col">Property ID</th>267* <th scope="col">Description</th>268* </tr>269* </thead>270*271* <tbody>272* <tr>273* <th scope="row">declaration-handler</th>274* <td> Used to see most DTD declarations except those treated275* as lexical ("document element name is ...") or which are276* mandatory for all SAX parsers (<em>DTDHandler</em>).277* The Object must implement <a href="ext/DeclHandler.html"278* ><em>org.xml.sax.ext.DeclHandler</em></a>.279* </td>280* </tr>281*282* <tr>283* <th scope="row">document-xml-version</th>284* <td> May be examined only during a parse, after the startDocument()285* callback has been completed; read-only. This property is a286* literal string describing the actual XML version of the document,287* such as "1.0" or "1.1".288* </td>289* </tr>290*291* <tr>292* <th scope="row">dom-node</th>293* <td> For "DOM Walker" style parsers, which ignore their294* <em>parser.parse()</em> parameters, this is used to295* specify the DOM (sub)tree being walked by the parser.296* The Object must implement the297* <em>org.w3c.dom.Node</em> interface.298* </td>299* </tr>300*301* <tr>302* <th scope="row">lexical-handler</th>303* <td> Used to see some syntax events that are essential in some304* applications: comments, CDATA delimiters, selected general305* entity inclusions, and the start and end of the DTD306* (and declaration of document element name).307* The Object must implement <a href="ext/LexicalHandler.html"308* ><em>org.xml.sax.ext.LexicalHandler</em></a>.309* </td>310* </tr>311*312* <tr>313* <th scope="row">xml-string</th>314* <td> Readable only during a parser callback, this exposes a <b>TBS</b>315* chunk of characters responsible for the current event.316* </td>317* </tr>318* </tbody>319* </table>320*321* <p>322* All of these standard properties are optional.323* XMLReader implementations are not required to support them.324*325* @apiNote The SAX API, originally developed at326* <a href="http://www.saxproject.org">the SAX Project</a>,327* has been defined by Java SE since 1.4.328*329* @since 1.4330*/331332package org.xml.sax;333334335