1
1
<?xml version='1.0' encoding='UTF-8'?>
3
* Copyright 1999-2006 The Apache Software Foundation.
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
2
17
<!DOCTYPE features SYSTEM 'dtd/settings.dtd'>
4
19
<desc name='Setting Features'>
6
21
If you have created a DOM document builder or a SAX parser using
7
the JAXP interfaces, you may have difficulty setting features and
8
properties directly using those interfaces. The following
9
instructions tell you how to set features on document builders
10
and SAX parsers created from the JAXP interfaces.
22
the JAXP interfaces, the following instructions tell you how to
23
set features on document builders and SAX parsers created from
13
27
The DocumentBuilderFactory interface contains a
14
<code>setAttribute(String,Object)</code> method which <em>may</em>
15
provide a means to set features and properties on the underyling
16
parser. However, it cannot be relied upon. Therefore, you must
17
use the Xerces DOMParser object directly. For example:
28
<code>setFeature(String,boolean)</code> method which
29
can be used to set features on the underlying parser.
19
<source>import org.apache.xerces.parsers.DOMParser;
20
import org.xml.sax.SAXException;
32
<source>import javax.xml.parsers.DocumentBuilderFactory;
33
import javax.xml.parsers.DocumentBuilder;
22
DOMParser parser = new DOMParser();
35
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
36
dbf.setNamespaceAware(true);
24
parser.setFeature("http://apache.org/xml/features/allow-java-encodings",
39
dbf.setFeature("http://apache.org/xml/features/allow-java-encodings",
27
catch (SAXException e) {
42
catch (ParserConfigurationException e) {
28
43
System.err.println("could not set parser feature");
31
Using the SAXParser interface in JAXP is better because you can
32
query the underlying XMLReader implementation directly and that
33
interface contains methods to set and query features and
34
properties. For example:
46
The SAXParserFactory interface contains a
47
<code>setFeature(String,boolean)</code> method which can be used
48
to set features on the underlying implementation of <code>XMLReader</code>.
49
Once you create the SAXParser you can retrieve the underlying
50
<code>XMLReader</code> allowing you to set and query features on it directly.
36
53
<source>import javax.xml.parsers.SAXParser;
37
54
import org.xml.sax.SAXException;
68
85
<see idref='namespace-prefixes'/>
69
86
<see idref='validation'/>
88
<feature name='http://xml.org/sax/features/use-entity-resolver2'
89
id='use-entity-resolver2'>
91
The methods of the org.xml.sax.ext.EntityResolver2 interface will be used when an object implementing
92
this interface is registered with the parser using setEntityResolver.
95
The methods of the org.xml.sax.ext.EntityResolver2 interface will not be used.
97
<default value='true'/>
98
<access general='read-write'/>
99
<since value='&ParserName; 2.7.0'/>
101
If the <link anchor="disallow-doctype-decl">disallow DOCTYPE declaration</link> feature is set to true
102
org.xml.sax.ext.EntityResolver2.getExternalSubset() will not be called when the document contains no
105
<see idref='disallow-doctype-decl'/>
106
<see idref='validation'/>
107
<see idref='nonvalidating.load-external-dtd'/>
71
109
<feature name='http://xml.org/sax/features/validation'
73
111
<true>Validate the document and report validity errors.</true>
101
139
<feature name='http://apache.org/xml/features/validation/schema'
102
140
id='validation.schema'>
103
<true>Turn on XML Schema validation by inserting XML Schema validator in the pipeline.
141
<true>Turn on XML Schema validation by inserting an XML Schema validator into the pipeline.
105
143
<false>Do not report validation errors against XML Schema.</false>
106
144
<default value='false'/>
107
145
<access parsing='read-only' not-parsing='read-write'/>
108
<note> Validation errors will only be reported if <link anchor="validation">validation feature</link> is set to true. For more information, please, refer to the <link idref='faq-pcfp'>FAQ</link>
146
<note> Validation errors will only be reported if the <link anchor="validation">validation feature</link> is set to true. For more information, please, refer to the <link idref='faq-pcfp'>FAQ</link>
149
Checking of constraints on a schema grammar which are either time-consuming or memory intensive
150
such as unique particle attribution will only occur if the
151
<link anchor="validation.schema-full-checking">schema full checking feature</link> is set to true.
110
153
<see idref='validation'/>
111
154
<see idref='validation.dynamic'/>
115
158
id='validation.schema-full-checking'>
117
160
Enable full schema grammar constraint checking, including checking
118
which may be time-consuming or memory intensive. Currently, particle
119
unique attribution constraint checking and particle derivation
120
resriction checking are controlled by this option.
161
which may be time-consuming or memory intensive. Currently, unique
162
particle attribution constraint checking and particle derivation
163
restriction checking are controlled by this option.
122
165
<false>Disable full constraint checking.</false>
123
166
<default value='false'/>
172
215
<see idref='validation.schema'/>
218
<feature name='http://apache.org/xml/features/validation/schema/ignore-xsi-type-until-elemdecl'
219
id='validation.schema.ignore-xsi-type-until-elemdecl'>
220
<true>xsi:type attributes will be ignored until a global element declaration has been found, at which point xsi:type attributes will be processed on the element for which the global element declaration was found as well as its descendants.</true>
221
<false>Do not ignore xsi:type attributes.</false>
222
<default value='false'/>
223
<access parsing='read-only' not-parsing='read-write'/>
224
<since value='&ParserName; 2.8.0'/>
225
<see idref='validation'/>
226
<see idref='validation.schema'/>
229
<feature name='http://apache.org/xml/features/generate-synthetic-annotations'
230
id='generate-synthetic-annotations'>
231
<true>Enable generation of synthetic annotations. A synthetic annotation will be generated when a schema component has non-schema attributes but no child annotation.</true>
232
<false>Do not generate synthetic annotations.</false>
233
<default value='false'/>
234
<access parsing='read-only' not-parsing='read-write'/>
235
<since value='&ParserName; 2.7.0'/>
236
<see idref='validation'/>
237
<see idref='validation.schema'/>
238
<see idref='validate-annotations'/>
241
<feature name='http://apache.org/xml/features/validate-annotations'
242
id='validate-annotations'>
243
<true>Schema annotations will be laxly validated against available schema components.</true>
244
<false>Do not validate schema annotations.</false>
245
<default value='false'/>
246
<access parsing='read-only' not-parsing='read-write'/>
247
<since value='&ParserName; 2.7.0'/>
248
<see idref='validation'/>
249
<see idref='validation.schema'/>
250
<see idref='generate-synthetic-annotations'/>
253
<feature name='http://apache.org/xml/features/honour-all-schemaLocations'
254
id='honour-all-schemaLocations'>
255
<true>All schema location hints will be used to locate the components for a given target namespace.</true>
256
<false>Only the first schema location hint encountered by the processor will be used to locate the components for a given target namespace.</false>
257
<default value='false'/>
258
<access parsing='read-only' not-parsing='read-write'/>
259
<since value='&ParserName; 2.7.0'/>
176
262
<feature name='http://xml.org/sax/features/external-general-entities'
177
263
id='external-general-entities'>
193
279
<access parsing='read-only' not-parsing='read-write'/>
194
280
<see idref='external-general-entities'/>
282
<feature name='http://apache.org/xml/features/validation/balance-syntax-trees'
283
id='validation.balance-syntax-trees'>
284
<true>Construct an optimal representation for DTD content models to significantly
285
reduce the likelihood a StackOverflowError will occur when large content
286
models are processed.</true>
288
Do not invest processing time to construct an optimal representation for DTD content models.
290
<default value='false'/>
291
<access parsing='read-only' not-parsing='read-write'/>
292
<since value='&ParserName; 2.8.0'/>
294
Enabling this feature may cost your application some performance when DTDs are
295
processed so it is recommended that it only be turned on when necessary.
298
<feature name='http://apache.org/xml/features/validation/id-idref-checking'
299
id='validation.id-idref-checking'>
300
<true>Enable checking of ID/IDREF constraints.</true>
302
Disable checking of ID/IDREF constraints. Validation will not fail if
303
there are non-unique ID values or dangling IDREF values in the document.
305
<default value='true'/>
306
<access parsing='read-only' not-parsing='read-write'/>
307
<since value='&ParserName; 2.8.0'/>
308
<note>This feature only applies to schema validation.</note>
309
<see idref='validation'/>
310
<see idref='validation.schema'/>
312
<feature name='http://apache.org/xml/features/validation/identity-constraint-checking'
313
id='validation.identity-constraint-checking'>
314
<true>Enable identity constraint checking.</true>
315
<false>Disable identity constraint checking.</false>
316
<default value='true'/>
317
<access parsing='read-only' not-parsing='read-write'/>
318
<since value='&ParserName; 2.8.0'/>
319
<see idref='validation'/>
320
<see idref='validation.schema'/>
322
<feature name='http://apache.org/xml/features/validation/unparsed-entity-checking'
323
id='validation.unparsed-entity-checking'>
324
<true>Check that each value of type ENTITY matches the name of an unparsed entity declared in the DTD.</true>
325
<false>Do not check that each value of type ENTITY matches the name of an unparsed entity declared in the DTD.</false>
326
<default value='true'/>
327
<access parsing='read-only' not-parsing='read-write'/>
328
<since value='&ParserName; 2.8.0'/>
329
<note>This feature only applies to schema validation.</note>
330
<see idref='validation'/>
331
<see idref='validation.schema'/>
196
333
<feature name='http://apache.org/xml/features/validation/warn-on-duplicate-attdef'
197
334
id='validation.warn-on-duplicate-attdef'>
198
335
<true>Report a warning when a duplicate attribute is re-declared.</true>
317
455
invalid URI characters (space, for example).
319
457
<default value='false'/>
458
<since value='&ParserName; 2.3.0'/>
321
460
It's recommended to set this feature to true if you want your
322
461
application/documents to be truly portable across different XML processors.
465
<feature name='http://apache.org/xml/features/xinclude'
467
<true>Enable XInclude processing.</true>
468
<false>Do not perform XInclude processing.</false>
469
<default value='false'/>
470
<since value='&ParserName; 2.7.0'/>
471
<see idref='xinclude.fixup-base-uris'/>
472
<see idref='xinclude.fixup-language'/>
475
<feature name='http://apache.org/xml/features/xinclude/fixup-base-uris'
476
id='xinclude.fixup-base-uris'>
477
<true>Perform base URI fixup as specified by the XInclude Recommendation.</true>
478
<false>Do not perform base URI fixup. The XInclude processor will not add xml:base attributes.</false>
479
<default value='true'/>
480
<since value='&ParserName; 2.7.0'/>
481
<see idref='xinclude'/>
484
<feature name='http://apache.org/xml/features/xinclude/fixup-language'
485
id='xinclude.fixup-language'>
486
<true>Perform language fixup as specified by the XInclude Recommendation.</true>
487
<false>Do not perform language fixup. The XInclude processor will not add xml:lang attributes.</false>
488
<default value='true'/>
489
<since value='&ParserName; 2.7.0'/>
490
<see idref='xinclude'/>
327
494
<fcategory name='DOM Features'>
420
587
can only be set to true.
590
<feature name='http://xml.org/sax/features/lexical-handler/parameter-entities'
591
id='lexical-handler.parameter-entities'>
593
Report the beginning and end of parameter entities to a registered LexicalHandler.
596
Do not report the beginning and end of parameter entities to a registered LexicalHandler.
598
<default value='true'/>
599
<since value='&ParserName; 2.7.0'/>
601
<feature name='http://xml.org/sax/features/is-standalone'
604
The document specified standalone="yes" in its XML declaration.
607
The document specified standalone="no" in its XML declaration or the
608
standalone document declaration was absent.
610
<access parsing='read-only' not-parsing='none'/>
611
<since value='&ParserName; 2.7.0'/>
613
<feature name='http://xml.org/sax/features/resolve-dtd-uris'
614
id='resolve-dtd-uris'>
616
The system identifiers passed to the notationDecl, unparsedEntityDecl, and
617
externalEntityDecl events will be absolutized relative to their base URIs before reporting.
620
System identifiers in declarations will not be absolutized before reporting.
622
<default value='true'/>
623
<since value='&ParserName; 2.7.0'/>
625
This feature does not apply to EntityResolver.resolveEntity(), which is not used to report declarations,
626
or to LexicalHandler.startDTD(), which already provides the non-absolutized URI.
629
<feature name='http://xml.org/sax/features/unicode-normalization-checking'
630
id='unicode-normalization-checking'>
632
Perform Unicode normalization checking (as described in section 2.13 and Appendix B
633
of the XML 1.1 Recommendation) and report normalization errors.
636
Do not report Unicode normalization errors.
638
<default value='false'/>
639
<since value='&ParserName; 2.7.0'/>
641
As there is currently no support for Unicode normalization checking, this
642
feature can only be set to false.
645
<feature name='http://xml.org/sax/features/use-attributes2'
646
id='use-attributes2'>
648
The Attributes objects passed by the parser in org.xml.sax.ContentHandler.startElement() implement the org.xml.sax.ext.Attributes2 interface.
651
The Attributes objects passed by the parser do not implement the org.xml.sax.ext.Attributes2 interface.
653
<access general='read-only'/>
654
<since value='&ParserName; 2.7.0'/>
656
Xerces-J will always report Attributes objects that also implement org.xml.sax.ext.Attributes2
657
so the value of this feature will always be true.
660
<feature name='http://xml.org/sax/features/use-locator2'
663
The Locator objects passed by the parser in org.xml.sax.ContentHandler.setDocumentLocator() implement the org.xml.sax.ext.Locator2 interface.
666
The Locator objects passed by the parser do not implement the org.xml.sax.ext.Locator2 interface.
668
<access general='read-only'/>
669
<since value='&ParserName; 2.7.0'/>
671
Xerces-J will always report Locator objects that also implement org.xml.sax.ext.Locator2
672
so the value of this feature will always be true.
675
<feature name='http://xml.org/sax/features/xmlns-uris'
678
When the namespace-prefixes feature is set to true, namespace declaration attributes
679
will be reported as being in the http://www.w3.org/2000/xmlns/ namespace.
682
Namespace declaration attributes are reported as having no namespace.
684
<default value='false'/>
685
<since value='&ParserName; 2.7.0'/>
686
<see idref='namespaces'/>
687
<see idref='namespace-prefixes'/>
689
<feature name='http://xml.org/sax/features/xml-1.1'
692
The parser supports both XML 1.1 and XML 1.0.
695
The parser supports only XML 1.0.
697
<access general='read-only'/>
698
<since value='&ParserName; 2.7.0'/>
700
The value of this feature will depend on whether the
701
parser configuration owned by the SAX parser is known
424
707
<fcategory name='XInclude Features (Experimental)'>
425
708
<feature name='http://xml.org/sax/features/allow-dtd-events-after-endDTD'