Question about extending libxmljs

46 views
Skip to first unread message

Brev

unread,
Oct 4, 2010, 5:17:51 PM10/4/10
to libxmljs
Hi all,

I'm working on a server-side DOM implementation for v8/nodejs, which
will use libxmljs as a foundation.

Marco has an example of how libxmljs could be augmented here:
http://gist.github.com/603881

This is pretty much the method I've been using.

I am running into a problem when libxmljs and the DOM have attributes
or methods with the same name:

- libxmljs has method: element.nextSibling()
- DOM has attribute: element.nextSibling

If I extend libxmljs.Element.prototype.nextSibling to achieve the DOM
attribute, I destroy the original libxmljs method. To fix this, I
have to make a renamed backup copy of the original, and thus break the
original libxmljs API. An example:

http://gist.github.com/610446

I guess I'd need a way to detect inside the function whether it was
invoked as a method or an attribute. But, I don't think you can have
both a value function, and a getter function - it's either/or.

Making these backup+renamed methods is ugly. It would still work if
my DOM library was separate from libxmljs. But if this was to be part
of libxmljs, this wouldn't cut it.

thanks for any ideas.

Brev

Marco Rogers

unread,
Oct 6, 2010, 8:46:49 AM10/6/10
to libxmljs
I see. In the DOM spec, nextSibling is a getter property instead of a
function. That sucks. Let me think on this for a bit. You could
also ask in the #nodejs irc and see if they have any ideas.

It may just be easier to change the libxmljs api to confirm to the w3c
spec. There are a couple of reasons I'm not sure about doing that
right now though. It seems convenient to use the specs that are
already available for javascript when it comes to xml. But those
specs are tied to the browser. Node can be a general purpose
scripting environment and can be used for many more things. I'm not
sureI want to carry around the baggage of that api without providing a
lower level one as well. Javascript is a very expressive language and
you can build nicer and simpler apis than the w3c ones.

But anyway, post a list of the functions/properties that are
problematic and lets take a look.

:Marco
Reply all
Reply to author
Forward
0 new messages