Optionalbase: string
The URL references resolve against, taken as it stands in place of the URL a response was retrieved from
A task converting a feed of XML documents, given as text or as responses, into a feed of parsed trees
RangeError If base is not a hierarchical identifier, that is a scheme followed by a
root-relative path, and so cannot serve as a resolution base
Error While the feed is consumed, whatever the source reports while producing documents, or whatever reading the body of a response reports
Creates an XML parser.
The generated task converts a feed of XML documents into a feed of parsed trees, one tree per document, so that a consumer works on the structure a document states rather than on its text. A document holding no text, or only whitespace, contributes no tree, as does a response carrying no body.
A body is decoded as the
charsetparameter of its content type states, and as UTF-8 where it states none, whatever the US-ASCII default carried by thetextmedia types. A byte order mark opening a document is stripped, both from text and from a body decoded under a Unicode charset.A response is read whatever it states about itself, so that a mis-declared source is diagnosed without being shut out: a content type that is not an XML one,
application/xml,text/xmlor a+xmlformat such asapplication/rss+xml, and a charset the platform doesn't decode are both reported to the log and the body read all the same, decoded as UTF-8 where the charset is not known. The report is the only sign a document is not what it was taken for, as parsing never fails.References drawn from a tree resolve by the standard rules without the request being tracked alongside it: the URL they resolve against is recorded as an
xml:baseattribute on every root element, and a root already declaring one keeps its own value, resolved against it.The
baseargument states that URL and is taken as it stands. Where it is left out, a response supplies the URL it was retrieved from, the one the request landed on rather than the one it was issued for. Nothing is recorded where neither states one, as for a document given as text or a synthesised response.The
baseargument is expected to be a hierarchical identifier, that is a scheme followed by a root-relative path: a relative reference or an opaque identifier such asurn:example:xis reported rather than recorded, as either would leave every reference drawn from the trees silently unresolved.Parsing is forgiving and never fails. The emitted tree is always structurally sound, since anything the source leaves unclosed is closed at the end of the input, but it may misrepresent malformed input rather than reject it: an unclosed element absorbs what follows as its descendants, an unterminated attribute value swallows the rest of the input, and the tree may carry any number of element children, none included. Consumers that require well-formed input must validate the emitted tree themselves.
The encoding declared by the XML prolog is ignored: a body is decoded as the content type states, so a document declaring one encoding and served under another is read under the served one.