javascript - html: 从DOMParser的Document中选择根元素(root element)

jsf

2018-03-25T19:00:40Z||2018-03-25T19:00:40Z

DOMParser.parseFromString返回一个Document对象。Document.documentElement返回根节点(HTMLElement类型).

const parser = new DOMParser();
const rootElement = parser.parseFromString(xml, 'application/xml').documentElement;