@auth0/xmldom

中文文档
0.1.23发布于 2021/03/02CommonJS零依赖近 30 天下载 29.7万

A W3C Standard XML DOM(Level2 CORE) implementation and parser(DOMParser/XMLSerializer).

原始使用文档
文档目录4 节
  1. Install:
  2. DOM level2 method and attribute:
  3. DOM level 3 support:
  4. DOM extension by xmldom

XMLDOM Build Status Coverage Status NPM version

A JavaScript implementation of W3C DOM for Node.js, Rhino and the browser. Fully compatible with W3C DOM level2; and some compatible with level3. Supports DOMParser and XMLSerializer interface such as in browser.

Install:

npm install xmldom

Example:

var DOMParser = require('xmldom').DOMParser;
var doc = new DOMParser().parseFromString(
    '<xml xmlns="a" xmlns:c="./lite">\n'+
        '\t<child>test</child>\n'+
        '\t<child></child>\n'+
        '\t<child/>\n'+
    '</xml>'
    ,'text/xml');
doc.documentElement.setAttribute('x','y');
doc.documentElement.setAttributeNS('./lite','c:x','y2');
var nsAttr = doc.documentElement.getAttributeNS('./lite','x')
console.info(nsAttr)
console.info(doc)

API Reference

  • DOMParser:

    parseFromString(xmlsource,mimeType)
    
    • options extension by xmldom(not BOM standard!!)
    //added the options argument
    new DOMParser(options)
    
    //errorHandler is supported
    new DOMParser({
        /**
         * locator is always need for error position info
         */
        locator:{},
        /**
         * you can override the errorHandler for xml parser
         * @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
         */
        errorHandler:{warning:function(w){console.warn(w)},error:callback,fatalError:callback}
        //only callback model
        //errorHandler:function(level,msg){console.log(level,msg)}
    })
        
    
  • XMLSerializer

    serializeToString(node)
    

DOM level2 method and attribute:

  • Node

     attribute:
         nodeValue|prefix
     readonly attribute:
         nodeName|nodeType|parentNode|childNodes|firstChild|lastChild|previousSibling|nextSibling|attributes|ownerDocument|namespaceURI|localName
     method:	
         insertBefore(newChild, refChild)
         replaceChild(newChild, oldChild)
         removeChild(oldChild)
         appendChild(newChild)
         hasChildNodes()
         cloneNode(deep)
         normalize()
         isSupported(feature, version)
         hasAttributes()
    
  • DOMImplementation

     method:
         hasFeature(feature, version)
         createDocumentType(qualifiedName, publicId, systemId)
         createDocument(namespaceURI, qualifiedName, doctype)
    
  • Document : Node

     readonly attribute:
         doctype|implementation|documentElement
     method:
         createElement(tagName)
         createDocumentFragment()
         createTextNode(data)
         createComment(data)
         createCDATASection(data)
         createProcessingInstruction(target, data)
         createAttribute(name)
         createEntityReference(name)
         getElementsByTagName(tagname)
         importNode(importedNode, deep)
         createElementNS(namespaceURI, qualifiedName)
         createAttributeNS(namespaceURI, qualifiedName)
         getElementsByTagNameNS(namespaceURI, localName)
         getElementById(elementId)
    
  • DocumentFragment : Node

  • Element : Node

     readonly attribute:
         tagName
     method:
         getAttribute(name)
         setAttribute(name, value)
         removeAttribute(name)
         getAttributeNode(name)
         setAttributeNode(newAttr)
         removeAttributeNode(oldAttr)
         getElementsByTagName(name)
         getAttributeNS(namespaceURI, localName)
         setAttributeNS(namespaceURI, qualifiedName, value)
         removeAttributeNS(namespaceURI, localName)
         getAttributeNodeNS(namespaceURI, localName)
         setAttributeNodeNS(newAttr)
         getElementsByTagNameNS(namespaceURI, localName)
         hasAttribute(name)
         hasAttributeNS(namespaceURI, localName)
    
  • Attr : Node

     attribute:
         value
     readonly attribute:
         name|specified|ownerElement
    
  • NodeList

     readonly attribute:
         length
     method:
         item(index)
    
  • NamedNodeMap

     readonly attribute:
         length
     method:
         getNamedItem(name)
         setNamedItem(arg)
         removeNamedItem(name)
         item(index)
         getNamedItemNS(namespaceURI, localName)
         setNamedItemNS(arg)
         removeNamedItemNS(namespaceURI, localName)
    
  • CharacterData : Node

     method:
         substringData(offset, count)
         appendData(arg)
         insertData(offset, arg)
         deleteData(offset, count)
         replaceData(offset, count, arg)
    
  • Text : CharacterData

     method:
         splitText(offset)
    
  • CDATASection

  • Comment : CharacterData

  • DocumentType

     readonly attribute:
         name|entities|notations|publicId|systemId|internalSubset
    
  • Notation : Node

     readonly attribute:
         publicId|systemId
    
  • Entity : Node

     readonly attribute:
         publicId|systemId|notationName
    
  • EntityReference : Node

  • ProcessingInstruction : Node

     attribute:
         data
     readonly attribute:
         target
    

DOM level 3 support:

  • Node

     attribute:
         textContent
     method:
         isDefaultNamespace(namespaceURI){
         lookupNamespaceURI(prefix)
    

DOM extension by xmldom

  • [Node] Source position extension;

     attribute:
         //Numbered starting from '1'
         lineNumber
         //Numbered starting from '1'
         columnNumber
    

版本与发布记录

@auth0/xmldom 共发布 4 个版本,首次发布于 2021/03/01;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.23latest2021/03/025 年前
0.1.222021/03/025 年前
0.1.202021/03/025 年前
0.1.212021/03/015 年前

关于 @auth0/xmldom 的常见问题

@auth0/xmldom 是什么?

A W3C Standard XML DOM(Level2 CORE) implementation and parser(DOMParser/XMLSerializer).

如何安装 @auth0/xmldom?

在项目目录运行 npm install @auth0/xmldom,或使用 pnpm add / yarn add / bun add。

@auth0/xmldom 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/auth0__xmldom 是否存在。

@auth0/xmldom 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@auth0/xmldom 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@auth0/xmldom 可以商用吗?

@auth0/xmldom 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@auth0/xmldom 的下载量有多少?

根据 npm 官方下载统计,@auth0/xmldom 在 2026/10/07 – 2026/11/05 这 30 天内被下载 297,408 次,日均约 9,914 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@auth0/xmldom 还在维护吗?

最新版本 0.1.23 发布于 2021/03/02(5 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/03/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。