|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
An interface to an object that is able to build, or augment, a DOM tree from various input sources.
DOMParser
provides an API for parsing XML and building the
corresponding DOM document structure. A DOMParser
instance
can be obtained by invoking the
DOMImplementationLS.createDOMParser()
method.
As specified in [DOM Level 3 Core] , when a document is first made available via the DOMParser:
Text
node for each block of text. The
Text
nodes are in "normal" form: only structure (e.g.
elements, comments, processing instructions, CDATA sections, and entity
references) separates Text
nodes, i.e., there are neither
adjacent nor empty Text
nodes.
value
and nodeValue
attributes of an
Attr
node initially return the XML 1.0
normalized value. However, if the parameters "
validate-if-schema" and "
datatype-normalization" are set to true
, depending on the attribute normalization
used, the attribute values may differ from the ones obtained by the XML
1.0 attribute normalization. If the parameters
data-type-normalization
is set to false
, the
XML 1.0 attribute normalization is guaranteed to occur, and if the
attributes list does not contain namespace declarations, the
attributes
attribute on Element
node represents
the property [attributes] defined in [XML Information set]
.
Asynchronous DOMParser
objects are expected to also
implement the events::EventTarget
interface so that event
listeners can be registered on asynchronous DOMParser
objects.
Events supported by asynchronous DOMParser
objects are:
DOMParser
finishes to load the document. See also
the definition of the LSLoadEvent
interface. DOMParser
signals a progress as a document is parsed. See
also the definition of the LSProgressEvent
interface. Note: All events defined in this specification use the
namespace URI "http://www.w3.org/2002/DOMLS"
.
While parsing an input source, errors are reported to the application
through the error handler (DOMParser.config
's "
error-handler" parameter). This specification does in no way try to define all possible
errors that can occur while parsing XML, or any other markup, but some
common error cases are defined. The types (DOMError.type
) of
errors and warnings defined by this specification are:
"unsupported-media-type" [fatal]
true
and an
unsupported media type is encountered. "unsupported-encoding" [fatal]
"doctype-not-allowed" [fatal]
true
and a doctype is encountered. "unknown-character-denormalization" [fatal]
false
and a character is encountered for which the
processor cannot determine the normalization properties. "unbound-namespace-in-entity" [warning]
true
and an unbound namespace prefix is
encounterd in an entity declaration. "pi-base-uri-not-preserved" [warning]
false
and the following XML file is parsed:
<!DOCTYPE root [ <!ENTITY e SYSTEM 'subdir/myentity.ent' ]> <root> &e; </root>And
subdir/myentity.ent
looks like this:
<one> <two/> </one> <?pi 3.14159?> <more/>
In addition to raising the defined errors and warnings, implementations are expected to raise implementation specific errors and warnings for any other error and warning cases such as IO errors (file not found, permission denied,...), XML well-formedness errors, and so on.
See also the Document Object Model (DOM) Level 3 Load and Save Specification.
Field Summary | |
static short |
ACTION_APPEND_AS_CHILDREN
Append the result of the parse operation as children of the context node. |
static short |
ACTION_INSERT_AFTER
Insert the result of the parse operation as the immediately following sibling of the context node. |
static short |
ACTION_INSERT_BEFORE
Insert the result of the parse operation as the immediately preceding sibling of the context node. |
static short |
ACTION_REPLACE
Replace the context node with the result of the parse operation. |
static short |
ACTION_REPLACE_CHILDREN
Replace all the children of the context node with the result of the parse operation. |
Method Summary | |
void |
abort()
Abort the loading of the document that is currently being loaded by the DOMParser . |
boolean |
getAsync()
true if the DOMParser is asynchronous,
false if it is synchronous. |
boolean |
getBusy()
true if the DOMParser is currently busy
loading a document, otherwise false . |
org.apache.xerces.dom3.DOMConfiguration |
getConfig()
The DOMConfiguration object used when parsing an input
source. |
DOMParserFilter |
getFilter()
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. |
Document |
parse(DOMInput is)
Parse an XML document from a resource identified by a DOMInput . |
Document |
parseURI(java.lang.String uri)
Parse an XML document from a location identified by a URI reference [IETF RFC 2396]. |
Node |
parseWithContext(DOMInput input,
Node context,
short action)
Parse an XML fragment from a resource identified by a DOMInput and insert the content into an existing
document at the position specified with the context and
action arguments. |
void |
setFilter(DOMParserFilter filter)
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. |
Field Detail |
public static final short ACTION_APPEND_AS_CHILDREN
Element
or a DocumentFragment
.public static final short ACTION_REPLACE_CHILDREN
Element
, a Document
, or a
DocumentFragment
.public static final short ACTION_INSERT_BEFORE
Element
or a
DocumentFragment
.public static final short ACTION_INSERT_AFTER
Element
or a
DocumentFragment
.public static final short ACTION_REPLACE
Element
or a
DocumentFragment
.Method Detail |
public org.apache.xerces.dom3.DOMConfiguration getConfig()
DOMConfiguration
object used when parsing an input
source. This DOMConfiguration
is specific to the parse
operation and no parameter values from this
DOMConfiguration
object are passed automatically to the
DOMConfiguration
object on the Document
that is created, or used, by the parse operation. The DOM application
is responsible for passing any needed parameter values from this
DOMConfiguration
object to the
DOMConfiguration
object referenced by the
Document
object.
DOMConfiguration
objects for DOMParser
adds or modifies the following parameters:
"charset-overrides-xml-encoding"
true
DOMInput
overrides
any encoding from the protocol. false
"disallow-doctype"
true
false
"ignore-unknown-character-denormalizations"
true
false
"infoset"
DOMConfiguration
for a description of
this parameter. Unlike in [DOM Level 3 Core]
, this parameter will default to true
for
DOMParser
. "namespaces"
true
false
"supported-media-types-only"
true
false
false
.public DOMParserFilter getFilter()
DOMConfiguration
parameters have been applied. For
example, if "
validate" is set to true
, the validation is done before invoking the
filter.public void setFilter(DOMParserFilter filter)
DOMConfiguration
parameters have been applied. For
example, if "
validate" is set to true
, the validation is done before invoking the
filter.public boolean getAsync()
true
if the DOMParser
is asynchronous,
false
if it is synchronous.public boolean getBusy()
true
if the DOMParser
is currently busy
loading a document, otherwise false
.public Document parse(DOMInput is) throws DOMException
DOMInput
.is
- The DOMInput
from which the source of the
document is to be read.DOMParser
is a synchronous
DOMParser
, the newly created and populated
Document
is returned. If the DOMParser
is
asynchronous, null
is returned since the document
object may not yet be constructed when this method returns.DOMException
- INVALID_STATE_ERR: Raised if the DOMParser
's
DOMParser.busy
attribute is true
.public Document parseURI(java.lang.String uri) throws DOMException
uri
- The location of the XML document to be read.DOMParser
is a synchronous
DOMParser
, the newly created and populated
Document
is returned. If the DOMParser
is
asynchronous, null
is returned since the document
object may not yet be constructed when this method returns.DOMException
- INVALID_STATE_ERR: Raised if the DOMParser.busy
attribute is true
.public Node parseWithContext(DOMInput input, Node context, short action) throws DOMException
DOMInput
and insert the content into an existing
document at the position specified with the context
and
action
arguments. When parsing the input stream, the
context node is used for resolving unbound namespace prefixes. The
context node's ownerDocument
node (or the node itself if
the node of type DOCUMENT_NODE
) is used to resolve
default attributes and entity references.
Document
node and the action
is ACTION_REPLACE_CHILDREN
, then the document that is
passed as the context node will be changed such that it's
xmlEncoding
, documentURI
,
xmlVersion
, actualEncoding
,
xmlStandalone
, and all other such attributes are set to
what they would be set to if the input source was parsed using
DOMParser.parse()
.
DOMParser
is asynchronous then the insertion
of the resulting DOM structure is atomic, e.g. the whole structure is
inserted only once the whole input stream is completely parsed
without errors.
ErrorHandler
instance associated with the "
error-handler" parameter of the DOMConfiguration
.
parseWithContext
, the values of the
following configuration parameters will be ignored and their default
values will always be used instead: "
validate", "
validate-if-schema", and "
whitespace-in-element-content".input
- The DOMInput
from which the source document
is to be read. The source document must be an XML fragment, i.e.
anything except a complete XML document (except in the case where
the context node of type DOCUMENT_NODE
, and the action
is ACTION_REPLACE_CHILDREN
), a DOCTYPE (internal
subset), entity declaration(s), notation declaration(s), or XML or
text declaration(s).context
- The node that is used as the context for the data that
is being parsed. This node must be a Document
node, a
DocumentFragment
node, or a node of a type that is
allowed as a child of an Element
node, e.g. it cannot
be an Attribute
node.action
- This parameter describes which action should be taken
between the new set of nodes being inserted and the existing
children of the context node. The set of possible actions is
defined in ACTION_TYPES
above.DOMException
- NOT_SUPPORTED_ERR: Raised if the DOMParser
doesn't
support this method.
DOMParser.busy
attribute is true
.public void abort()
DOMParser
. If the DOMParser
is
currently not busy, a call to this method does nothing.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |