Most visited

Recently visited

Added in API level 8

DOMConfiguration

public interface DOMConfiguration

org.w3c.dom.DOMConfiguration


DOMConfiguration界面表示文档的配置并维护一个可识别参数的表格。 使用该配置,可以更改Document.normalizeDocument()行为,例如用CDATASection节点替换Text节点或指定在请求验证Document时必须使用的模式类型。 DOMConfiguration对象也用于DOMParserDOMSerializer接口中的[ DOM Level 3 Load and Save ]。

DOMConfiguration对象使用的参数名称在整个DOM级别3规范中定义。 名称不区分大小写。 为了避免可能的冲突,作为惯例,引用DOM规范之外定义的参数的名称应该是唯一的。 由于参数作为属性公开,因此建议使用名称' - '(HYPHEN-MINUS)后面的5.16节[Unicode]标识符,但不会由DOM实施实施。 DOM级别3核心实现需要识别本规范中定义的所有参数。 实现可能还需要一些参数值。 请参阅参数的定义以了解是否必须支持某个值。

注意:参数与SAX2 [ SAX ]中使用的特征和属性相似。

DOM中定义的以下参数列表:

"canonical-form"
true
[ optional] Canonicalize the document according to the rules specified in [ Canonical XML], such as removing the DocumentType node (if any) from the tree, or removing superfluous namespace declarations from each element. Note that this is limited to what can be represented in the DOM; in particular, there is no way to specify the order of the attributes in the DOM. In addition, Setting this parameter to true will also set the state of the parameters listed below. Later changes to the state of one of those parameters will revert "canonical-form" back to false. Parameters set to false: "entities", " normalize-characters", "cdata-sections". Parameters set to true: "namespaces", "namespace-declarations", "well-formed", "element-content-whitespace". Other parameters are not changed unless explicitly specified in the description of the parameters.
false
[ required] ( default)Do not canonicalize the document.
"cdata-sections"
true
[ required] ( default)Keep CDATASection nodes in the document.
false
[ required]Transform CDATASection nodes in the document into Text nodes. The new Text node is then combined with any adjacent Text node.
"check-character-normalization"
true
[ optional] Check if the characters in the document are fully normalized, as defined in appendix B of [ XML 1.1]. When a sequence of characters is encountered that fails normalization checking, an error with the DOMError.type equals to "check-character-normalization-failure" is issued.
false
[ required] ( default)Do not check if characters are normalized.
"comments"
true
[ required] ( default)Keep Comment nodes in the document.
false
[ required]Discard Comment nodes in the document.
"datatype-normalization"
true
[ optional] Expose schema normalized values in the tree, such as XML Schema normalized values in the case of XML Schema. Since this parameter requires to have schema information, the "validate" parameter will also be set to true. Having this parameter activated when "validate" is false has no effect and no schema-normalization will happen.

注意:由于文档包含XML 1.0处理的结果,因此此参数不适用于[ XML 1.0 ]的第3.3.3节中定义的属性值标准化,仅适用于文档类型定义(DTD)以外的模式语言。

false
[ required] ( default) Do not perform schema normalization on the tree.
"element-content-whitespace"
true
[ required] ( default)Keep all whitespaces in the document.
false
[ optional] Discard all Text nodes that contain whitespaces in element content, as described in [element content whitespace]. The implementation is expected to use the attribute Text.isElementContentWhitespace to determine if a Text node should be discarded or not.
"entities"
true
[ required] ( default)Keep EntityReference nodes in the document.
false
[ required] Remove all EntityReference nodes from the document, putting the entity expansions directly in their place. Text nodes are normalized, as defined in Node.normalize. Only unexpanded entity references are kept in the document.

注意:此参数不影响 Entity节点。

"error-handler"
[ required] Contains a DOMErrorHandler object. If an error is encountered in the document, the implementation will call back the DOMErrorHandler registered using this parameter. The implementation may provide a default DOMErrorHandler object. When called, DOMError.relatedData will contain the closest node to where the error occurred. If the implementation is unable to determine the node where the error occurs, DOMError.relatedData will contain the Document node. Mutations to the document from within an error handler will result in implementation dependent behavior.
"infoset"
true
[ required]Keep in the document the information defined in the XML Information Set [ XML Information Set] .This forces the following parameters to false: " validate-if-schema", "entities", "datatype-normalization", "cdata-sections ".This forces the following parameters to true: " namespace-declarations", "well-formed", "element-content-whitespace", " comments", "namespaces".Other parameters are not changed unless explicitly specified in the description of the parameters. Note that querying this parameter with getParameter returns true only if the individual parameters specified above are appropriately set.
false
Setting infoset to false has no effect.
"namespaces"
true
[ required] ( default) Perform the namespace processing as defined in .
false
[ optional] Do not perform the namespace processing.
"namespace-declarations"
This parameter has no effect if the parameter "namespaces" is set to false.
true
[ required] ( default) Include namespace declaration attributes, specified or defaulted from the schema, in the document. See also the sections "Declaring Namespaces" in [ XML Namespaces] and [ XML Namespaces 1.1] .
false
[ required]Discard all namespace declaration attributes. The namespace prefixes ( Node.prefix) are retained even if this parameter is set to false.
"normalize-characters"
true
[ optional] Fully normalized the characters in the document as defined in appendix B of [ XML 1.1].
false
[ required] ( default)Do not perform character normalization.
"schema-location"
[ optional] Represent a DOMString object containing a list of URIs, separated by whitespaces (characters matching the nonterminal production S defined in section 2.3 [ XML 1.0]), that represents the schemas against which validation should occur, i.e. the current schema. The types of schemas referenced in this list must match the type specified with schema-type, otherwise the behavior of an implementation is undefined. The schemas specified using this property take precedence to the schema information specified in the document itself. For namespace aware schema, if a schema specified using this property and a schema specified in the document instance (i.e. using the schemaLocation attribute) in a schema document (i.e. using schema import mechanisms) share the same targetNamespace, the schema specified by the user using this property will be used. If two schemas specified using this property share the same targetNamespace or have no namespace, the behavior is implementation dependent. If no location has been provided, this parameter is null.

注意:除非设置了“模式类型”参数值,否则将忽略"schema-location"参数。 强烈建议设置Document.documentURI以便实现可以成功解析任何引用的外部实体。

"schema-type"
[ optional] Represent a DOMString object containing an absolute URI and representing the type of the schema language used to validate a document against. Note that no lexical checking is done on the absolute URI. If this parameter is not set, a default value may be provided by the implementation, based on the schema languages supported and on the schema language used at load time. If no value is provided, this parameter is null.

注意:对于XML Schema [ XML Schema Part 1 ],应用程序必须使用值"http://www.w3.org/2001/XMLSchema" 对于XML DTD [ XML 1.0 ],应用程序必须使用值"http://www.w3.org/TR/REC-xml" 其他模式语言超出了W3C的范围,因此应该推荐绝对URI以使用此方法。

"split-cdata-sections"
true
[ required] ( default)Split CDATA sections containing the CDATA section termination marker ']]>'. When a CDATA section is split a warning is issued with a DOMError.type equals to "cdata-sections-splitted" and DOMError.relatedData equals to the first CDATASection node in document order resulting from the split.
false
[ required]Signal an error if a CDATASection contains an unrepresentable character.
"validate"
true
[ optional] Require the validation against a schema (i.e. XML schema, DTD, any other type or representation of schema) of the document as it is being normalized as defined by [ XML 1.0]. If validation errors are found, or no schema was found, the error handler is notified. Schema-normalized values will not be exposed according to the schema in used unless the parameter "datatype-normalization" is true. This parameter will reevaluate:
  • Attribute nodes with Attr.specified equals to false, as specified in the description of the Attr interface;
  • The value of the attribute Text.isElementContentWhitespace for all Text nodes;
  • The value of the attribute Attr.isId for all Attr nodes;
  • The attributes Element.schemaTypeInfo and Attr.schemaTypeInfo.

注意: “validate-if-schema”和“validate”是互斥的,将其中一个设置为true会将另一个设置为false 验证文档时,应用程序还应该考虑将参数“格式良好”设置为true (该选项的默认值)。

false
[ required] ( default) Do not accomplish schema processing, including the internal subset processing. Default attribute values information are kept. Note that validation might still happen if "validate-if-schema" is true .
"validate-if-schema"
true
[ optional]Enable validation only if a declaration for the document element can be found in a schema (independently of where it is found, i.e. XML schema, DTD, or any other type or representation of schema). If validation is enabled, this parameter has the same behavior as the parameter "validate" set to true.

注意: “validate-if-schema”和“validate”是互斥的,将其中一个设置为 true会将另一个设置为 false

false
[ required] ( default) No schema processing should be performed if the document has a schema, including internal subset processing. Default attribute values information are kept. Note that validation must still happen if "validate " is true.
"well-formed"
true
[ required] ( default) Check if all nodes are XML well formed according to the XML version in use in Document.xmlVersion:
  • check if the attribute Node.nodeName contains invalid characters according to its node type and generate a DOMError of type "wf-invalid-character-in-node-name", with a DOMError.SEVERITY_ERROR severity, if necessary;
  • check if the text content inside Attr, Element, Comment, Text, CDATASection nodes for invalid characters and generate a DOMError of type "wf-invalid-character", with a DOMError.SEVERITY_ERROR severity, if necessary;
  • check if the data inside ProcessingInstruction nodes for invalid characters and generate a DOMError of type "wf-invalid-character", with a DOMError.SEVERITY_ERROR severity, if necessary;
false
[ optional] Do not check for XML well-formedness.

与实体关联的系统标识符的解析使用Document.documentURI完成。 但是,当DOM实现支持[ DOM Level 3 Load and Save ]中定义的功能“LS”时,参数“resource-resolver”也可以用于连接到Document节点的DOMConfiguration对象。 如果设置了此参数,则Document.normalizeDocument()将调用资源解析器,而不是使用Document.documentURI

另见 Document Object Model (DOM) Level 3 Core Specification

Summary

Public methods

abstract boolean canSetParameter(String name, Object value)

检查是否支持将参数设置为特定值。

abstract Object getParameter(String name)

如果已知,则返回参数的值。

abstract DOMStringList getParameterNames()

这个 DOMConfiguration对象所支持的参数列表,并且至少有一个值可以由应用程序设置。

abstract void setParameter(String name, Object value)

设置参数的值。

Public methods

canSetParameter

Added in API level 8
boolean canSetParameter (String name, 
                Object value)

检查是否支持将参数设置为特定值。

Parameters
name String: The name of the parameter to check.
value Object: An object. if null, the returned value is true.
Returns
boolean true if the parameter could be successfully set to the specified value, or false if the parameter is not recognized or the requested value is not supported. This does not change the current value of the parameter itself.

getParameter

Added in API level 8
Object getParameter (String name)

如果已知,则返回参数的值。

Parameters
name String: The name of the parameter.
Returns
Object The current object associated with the specified parameter or null if no object has been associated or if the parameter is not supported.
Throws
DOMException NOT_FOUND_ERR: Raised when the parameter name is not recognized.

getParameterNames

Added in API level 8
DOMStringList getParameterNames ()

DOMConfiguration对象支持的参数的列表,并且应用程序可以为其设置至少一个值。 请注意,该列表还可以包含在本规范之外定义的参数名称。

Returns
DOMStringList

setParameter

Added in API level 8
void setParameter (String name, 
                Object value)

设置参数的值。

Parameters
name String: The name of the parameter to set.
value Object: The new value or null if the user wishes to unset the parameter. While the type of the value parameter is defined as DOMUserData, the object type must match the type defined by the definition of the parameter. For example, if the parameter is "error-handler", the value must be of type DOMErrorHandler.
Throws
DOMException NOT_FOUND_ERR: Raised when the parameter name is not recognized.
NOT_SUPPORTED_ERR: Raised when the parameter name is recognized but the requested value cannot be set.
TYPE_MISMATCH_ERR: Raised if the value type for this parameter name is incompatible with the expected value type.

Hooray!