LSParser
provides an API for parsing XML and building the
corresponding DOM document structure. A LSParser
instance
can be obtained by invoking the
DOMImplementationLS.createLSParser()
method.
As specified in [DOM Level 3 Core] , when a document is first made available via the LSParser:
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
"datatype-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 LSParser
objects are expected to also
implement the events::EventTarget
interface so that event
listeners can be registered on asynchronous LSParser
objects.
Events supported by asynchronous LSParser
objects are:
LSParser
finishes to load the document. See also the
definition of the LSLoadEvent
interface. LSParser
signals progress as data is parsed. This
specification does not attempt to define exactly when progress events
should be dispatched. That is intentionally left as
implementation-dependent. Here is one example of how an application might
dispatch progress events: Once the parser starts receiving data, a
progress event is dispatched to indicate that the parsing starts. From
there on, a progress event is dispatched for every 4096 bytes of data
that is received and processed. This is only one example, though, and
implementations can choose to dispatch progress events at any time while
parsing, or not dispatch them at all. 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 (LSParser.domConfig
'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:
"check-character-normalization-failure" [error]
"doctype-not-allowed" [fatal]
true
and a doctype is encountered. "no-input-specified" [fatal]
LSInput
object. "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
contains:
<one> <two/> </one> <?pi 3.14159?> <more/>
"unbound-prefix-in-entity" [warning]
true
and an unbound namespace prefix is
encountered in an entity's replacement text. Raising this warning is not
enforced since some existing parsers may not recognize unbound namespace
prefixes in the replacement text of entities. "unknown-character-denormalization" [fatal]
false
and a character is encountered for which the
processor cannot determine the normalization properties. "unsupported-encoding" [fatal]
"unsupported-media-type" [fatal]
true
and an unsupported media type is encountered. 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.
Modifier and Type | Field and Description |
---|---|
public static final short | ACTION_APPEND_AS_CHILDREN
Append the result of the parse operation as children of the context node. |
public static final short | ACTION_INSERT_AFTER
Insert the result of the parse operation as the immediately following sibling of the context node. |
public static final short | ACTION_INSERT_BEFORE
Insert the result of the parse operation as the immediately preceding sibling of the context node. |
public static final short | ACTION_REPLACE
Replace the context node with the result of the parse operation. |
public static final short | ACTION_REPLACE_CHILDREN
Replace all the children of the context node with the result of the parse operation. |
Modifier and Type | Method and Description |
---|---|
public void | |
public boolean | |
public boolean | |
public DOMConfiguration | |
public LSParserFilter | getFilter()
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. |
public Document | Returns: If theLSParser is a synchronous
LSParser , the newly created and populated
Document is returned. If the LSParser is
asynchronous, null is returned since the document
object may not yet be constructed when this method returns.The input)LSInput from which the source of the
document is to be read.Parse an XML document from a resource identified by a
|
public Document | Returns: If theLSParser is a synchronous
LSParser , the newly created and populated
Document is returned, or null if an error
occurred. If the LSParser is asynchronous,
null is returned since the document object may not yet
be constructed when this method returns.The location of the XML document to be read. uri)Parse an XML document from a location identified by a URI reference [IETF RFC 2396]. |
public Node | Returns: Return the node that is the result of the parse operation. If the result is more than one top-level node, the first one is returned.The input, Node LSInput 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).The node that is used as the context for the data
that is being parsed. This node must be a contextArg, short 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.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)ACTION_TYPES above.Parse an XML fragment from a resource identified by a
|
public void | setFilter(LSParserFilter filter)
When a filter is provided, the implementation will call out to the filter as it is constructing the DOM tree structure. |
ACTION_APPEND_AS_CHILDREN | back to summary |
---|---|
public static final short ACTION_APPEND_AS_CHILDREN Append the result of the parse operation as children of the context
node. For this action to work, the context node must be an
|
ACTION_INSERT_AFTER | back to summary |
---|---|
public static final short ACTION_INSERT_AFTER Insert the result of the parse operation as the immediately following
sibling of the context node. For this action to work the context
node's parent must be an |
ACTION_INSERT_BEFORE | back to summary |
---|---|
public static final short ACTION_INSERT_BEFORE Insert the result of the parse operation as the immediately preceding
sibling of the context node. For this action to work the context
node's parent must be an |
ACTION_REPLACE | back to summary |
---|---|
public static final short ACTION_REPLACE Replace the context node with the result of the parse operation. For
this action to work, the context node must have a parent, and the
parent must be an |
ACTION_REPLACE_CHILDREN | back to summary |
---|---|
public static final short ACTION_REPLACE_CHILDREN Replace all the children of the context node with the result of the
parse operation. For this action to work, the context node must be an
|
abort | back to summary |
---|---|
public void abort() Abort the loading of the document that is currently being loaded by
the |
getAsync | back to summary |
---|---|
public boolean getAsync()
|
getBusy | back to summary |
---|---|
public boolean getBusy()
|
getDomConfig | back to summary |
---|---|
public DOMConfiguration getDomConfig() The
|
getFilter | back to summary |
---|---|
public LSParserFilter getFilter() When a filter is provided, the implementation will call out to the
filter as it is constructing the DOM tree structure. The filter can
choose to remove elements from the document being constructed, or to
terminate the parsing early.
|
parse | back to summary |
---|---|
public Document parse(LSInput input) throws DOMException, LSException Parse an XML document from a resource identified by a
|
parseURI | back to summary |
---|---|
public Document parseURI(String uri) throws DOMException, LSException Parse an XML document from a location identified by a URI reference [IETF RFC 2396]. If the URI contains a fragment identifier (see section 4.1 in [IETF RFC 2396]), the behavior is not defined by this specification, future versions of this specification may define the behavior.
|
parseWithContext | back to summary |
---|---|
public Node parseWithContext(LSInput input, Node contextArg, short action) throws DOMException, LSException Parse an XML fragment from a resource identified by a
|
setFilter | back to summary |
---|---|
public void setFilter(LSParserFilter filter) When a filter is provided, the implementation will call out to the
filter as it is constructing the DOM tree structure. The filter can
choose to remove elements from the document being constructed, or to
terminate the parsing early.
|