Since version 0.7.0 this package is published to npm as @xmldom/xmldom and no longer as xmldom, because we are no longer able to publish xmldom. For better readability in the docs, we will continue to talk about this library as "xmldom".
new DOMParser().parseFromString(xml, mimeType) => Document
create, access and modify a DOM tree
new DOMImplementation().createDocument(...) => Document
serialize a DOM tree back into an XML string
new XMLSerializer().serializeToString(node) => string
The target runtimes xmldom supports are currently Node >= v14.6 (and very likely any other ES5 compatible runtime).
When deciding how to fix bugs or implement features, xmldom tries to stay as close as possible to the various related specifications/standards.
As indicated by the version starting with 0., this implementation is not feature complete and some implemented features differ from what the specifications describe. Issues and PRs for such differences are always welcome, even when they only provide a failing test case.
This project was forked from it's original source in 2019, more details about that transition can be found in the CHANGELOG.
// the options argument can be used to modify behavior// for more details check the documentation on the code or type definition new DOMParser(options)
All DOM node types listed below are exported for use with instanceof (e.g. node instanceof Text).
They cannot be constructed directly — use the Document factory methods (createTextNode, createComment, createDocumentFragment, …) instead.
The original author claims that xmldom implements [DOM Level 2] in a "fully compatible" way and some parts of [DOM Level 3], but there are not enough tests to prove this. Both Specifications are now superseded by the [DOM Level 4 aka Living standard] wich has a much broader scope than xmldom.
In the past, there have been multiple (even breaking) changes to align xmldom with the living standard,
so if you find a difference that is not documented, any contribution to resolve the difference is very welcome (even just reporting it as an issue).
xmldom implements the following interfaces:
Attr
CDATASection
CharacterData
Comment
Document
DocumentFragment
DocumentType
DOMException
DOMImplementation
Element
Entity
EntityReference
LiveNodeList
NamedNodeMap
Node
NodeList
Notation
ProcessingInstruction
Text
more details are available in the (incomplete) API Reference section.
HTML
xmldom does not have any goal of supporting the full spec, but it has some capability to parse, report and serialize things differently when it is told to parse HTML (by passing the HTML namespace).
SAX, XML, XMLNS
xmldom has an own SAX parser implementation to do the actual parsing, which implements some interfaces in alignment with the Java interfaces SAX defines: