JSPM

xml-parse-from-string

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1672335
  • Score
    100M100P100Q194914F
  • License MIT

DOMParser.parseFromString for XML with IE8 fallback

Package Exports

  • xml-parse-from-string

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (xml-parse-from-string) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

xml-parse-from-string

stable

A light browser wrapper around DOMParser.parseFromString for XML, with fallback for IE8 and other browsers.

  • attempts to use DOMParser with "application/xml"
  • falls back to ActiveXObject('Microsoft.XMLDOM')
  • then falls back to createElement / innerHTML
var parseXML = require('xml-parse-from-string')

var str = '<root><foobar id="blah"></foobar></root>'
var doc = parseXML(str)
var tag = doc.getElementsByTagName('foobar')[0]

console.log(tag.getAttribute('id')) // -> "blah"

Be wary of subtle differences between implementations, such as case-sensitivity in attribute.nodeName.

PRs for Node version welcome.

Usage

NPM

root = parse(str)

Parses the string as XML and returns the root element as a DOM element, so you can do operations similar to document.getElementById, document.getElementsByTagName, and so forth.

License

MIT, see LICENSE.md for details.