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

Tree adapter for DOM #49

Closed
gagern opened this issue May 18, 2015 · 6 comments
Closed

Tree adapter for DOM #49

gagern opened this issue May 18, 2015 · 6 comments

Comments

@gagern
Copy link

gagern commented May 18, 2015

It would be nice if we could have an implementation-agnostic tree adaptor for DOM.
That way, one could use parse5 to load the document, then use all the DOM manipulating tools out there to tweak the data, and finally serialize things again using parse5. Or just do one of parsing and serialization using parse5, the other with something different.

@inikulin
Copy link
Owner

jsdom?

@gagern
Copy link
Author

gagern commented May 18, 2015

Adaptor for jsdom, xmldom, libxml-dom, …

In case you wanted to suggest jsdom as an alternative: sure, it can provide similar functionality, but the fact that the latest version requires io.js makes me reluctant to use it. And parsing to jsdom just so you can import the node into some other DOM implementation you're working with doesn't look attractive either. On the other hand, another tree adaptor would be a fairly easy affair. Should I make this a pull request?

@inikulin
Copy link
Owner

Well, seems like I don't quite understand what you want. Can you illiustrate it via some code snippets, please?

@gagern
Copy link
Author

gagern commented Jun 12, 2015

What I had in mind was something like this:

var parser = new Parser(new DomTreeAdapter(new xmldom.DOMImplementation()));

where DomTreeAdapter would be a new class shipped with parse5, and its constructor argument could be any object satisfying the DOMImplementation specification. But I now had a closer look and realized that on the one hand, libxml-dom apparently doesn't offer such a DOM implementation class, so the number of users would be rather small.

On the other hand, parse5 does object creation significantly different from what the DOM specs envision, so the effort to make things work out would be considerable. In particular, one would have to know the name (and namespace) of the root element before creating the document, and one would have to pass the document as an adapter function argument whenever constructing new elements. Probably not worth the effort just now. I thought this would be simpler, thus my suggestion.

Feel free to close if you don't want to pursue this either.

@inikulin
Copy link
Owner

DOM has a much more complicated connection with the HTML parser than this. I suggest you to keep an eye on JSDOM project, which is the most complete and spec-compliant pure-js DOM implementation at the moment.

@nrkn
Copy link

nrkn commented Jul 6, 2016

I had need of something like this

https://github.com/nrkn/dom-treeadapter/

I'm not actually using it with parse5 though - I've adopted the parse5 TreeAdapter interface throughout another project and I'm using it to map between two different DOM structures. Here's the mapper I'm using:

https://github.com/nrkn/treeadapter-mapper

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

3 participants