Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API should support an input string #1

Closed
sosna opened this issue Apr 22, 2016 · 2 comments
Closed

API should support an input string #1

sosna opened this issue Apr 22, 2016 · 2 comments

Comments

@sosna
Copy link

sosna commented Apr 22, 2016

Thanks for this nice library :).

I see the method mapSDMXMLResponse expects a DOM object as input. Could the library also accept a string as input and internally build a DOM object out of it? That would ease the work of the clients a bit. Thanks!

@airosa
Copy link
Owner

airosa commented Apr 22, 2016

Thanks!

It looks like this could be possible as you should be able to parse XML from a string using the parseFromString method from the DOMParser object. All relatively recent browsers should support this.

var parser = new DOMParser();
var doc = parser.parseFromString(stringContainingXMLSource, "application/xml");

Also looks like DOMParser is supported for Node in this package: https://www.npmjs.com/package/xmldom.

@airosa airosa closed this as completed in c315b3d Apr 24, 2016
@airosa
Copy link
Owner

airosa commented Apr 24, 2016

DOMParser is now used internally to convert the xml source to document object. Native DOMParser in the browsers and xmldom DOMParser in Node.

Turns out that xmldom does indeed work very well for this use case but it is not 100% compatible with DOM and JSDOM. For example:

  • getElementsByTagNameNS works differently when passing null as the namespace.
  • attributes are not accessible by name (like element.attributes.foo)
  • getAttribute returns empty string if attribute does not exist
  • childNodes return null if element does not have children
  • childNodes may include more nodes (extra text nodes)

However all in all a very nice library

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants