xmlns issues

47 views
Skip to first unread message

Sam Ruby

unread,
Jan 19, 2011, 11:22:30 AM1/19/11
to jsdom
I've begun to implement an xml5 parser in node.js based on jsdom, and
am looking to build upon it to produce feed reader software, and am
running into issues, particularly dealing with namespaces.

Xml5 is a spec'ed out version of xml with HTML5-style error recovery:

http://code.google.com/p/xml5/

I've begun porting it to node.js:

https://github.com/rubys/xml5/tree/master/lib.js

I've found a number of issues with the setting of things like prefix:

https://github.com/tmpvar/jsdom/issues#issue/124

And I find that I can't use setAttributeNS for things like xml:lang:

> Error
> at /home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:19:11
> at Object.setAttributeNS (/home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:233:3)
> at EventEmitter.do_token (/home/rubys/git/xml5/lib.js/parser.js:77:18)
> at EventEmitter.<anonymous> (/home/rubys/git/xml5/lib.js/parser.js:136:30)
> at EventEmitter.emit (events:31:17)
> at EventEmitter.emitToken (/home/rubys/git/xml5/lib.js/tokenizer.js:85:7)
> at EventEmitter.emit_current_token (/home/rubys/git/xml5/lib.js/tokenizer.js:1536:7)
> at EventEmitter.empty_tag_state (/home/rubys/git/xml5/lib.js/tokenizer.js:1335:8)
> at EventEmitter.<anonymous> (/home/rubys/git/xml5/lib.js/tokenizer.js:72:24)
> at EventEmitter.emit (events:28:17)

Working around this, I find that I can call createAttributeNode but
there is no ability provided to call setAttributeNode.

At the moment, I've been monkey-patching:

https://github.com/rubys/xml5/blob/master/lib.js/testrunner.js

But I would like a more sustainable solution. Is there some place to
discuss these issues, or should I simply fork the project and submit
pull requests? I'm quite willing, but my preference is for some
discussion before I dive in as am I am not sure what the best way to,
for example, disable functionality like automatic uppercasing of node
names would be. I'd also like some description as to how to run the
tests.

> $ node test/runner.js
>
> node.js:63
> throw e;
> ^
> Error: Cannot find module 'mjsunit.runner/runner'
> at loadModule (node.js:275:15)
> at require (node.js:411:14)
> at Object.<anonymous> (/home/rubys/git/jsdom/test/runner.js:195:1)
> at Module._compile (node.js:462:23)
> at Module._loadScriptSync (node.js:469:10)
> at Module.loadSync (node.js:338:12)
> at Object.runMain (node.js:522:24)
> at Array.<anonymous> (node.js:756:12)
> at EventEmitter._tickCallback (node.js:55:22)
> at node.js:773:9

I'm new to node.js, familiar with both the W3C DOM and JavaScript, and
I see test/mjsunit.js in jsdom, but I don't know the magic incantation
needed to run the tests.

- Sam Ruby

P.S. A sketch of where I am headed:

http://intertwingly.net/blog/2011/01/17/Planetary-Exploration

Elijah Insua

unread,
Jan 22, 2011, 4:32:33 PM1/22/11
to js...@googlegroups.com
And I find that I can't use setAttributeNS for things like xml:lang:

> Error
>     at /home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:19:11
>     at Object.setAttributeNS (/home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:233:3)
>     at EventEmitter.do_token (/home/rubys/git/xml5/lib.js/parser.js:77:18)
>     at EventEmitter.<anonymous> (/home/rubys/git/xml5/lib.js/parser.js:136:30)
>     at EventEmitter.emit (events:31:17)
>     at EventEmitter.emitToken (/home/rubys/git/xml5/lib.js/tokenizer.js:85:7)
>     at EventEmitter.emit_current_token (/home/rubys/git/xml5/lib.js/tokenizer.js:1536:7)
>     at EventEmitter.empty_tag_state (/home/rubys/git/xml5/lib.js/tokenizer.js:1335:8)
>     at EventEmitter.<anonymous> (/home/rubys/git/xml5/lib.js/tokenizer.js:72:24)
>     at EventEmitter.emit (events:28:17)

That is a strange error, do you think you could provide a bit more information? 
 
Working around this, I find that I can call createAttributeNode but
there is no ability provided to call setAttributeNode.

I assume you mean setAttributeNS
 
At the moment, I've been monkey-patching:

https://github.com/rubys/xml5/blob/master/lib.js/testrunner.js

But I would like a more sustainable solution.  

Agreed, I'm slowly but surely implementing xmlns support in jsdom as of HEAD jsdom passes 64% of the DOM level 2 core tests (100 tests failing).
 
Is there some place to discuss these issues, or should I simply fork the project and submit
pull requests?

Feel free to post here, or raise issues on github.  As for patches, I readily apply good patches (new code needs to be unit tested).
 
I'm quite willing, but my preference is for some discussion before I dive in as am I am not sure what the best way to,
for example, disable functionality like automatic uppercasing of node names would be.

There is a whole slew of tests in level1/core that ensure that this behavior is correct.  I'm pretty sure the default is to maintain the casing of node names, but I may be mistaken.  (https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/level1/core.js#L313-323)
 
> Error: Cannot find module 'mjsunit.runner/runner'
 
Ah, just run an `npm install mjsunit.runner` you may also want to install htmlparser (`npm install htmlparser`)
 
I'm new to node.js

Welcome! 

-- Elijah

Sam Ruby

unread,
Jan 22, 2011, 4:49:32 PM1/22/11
to js...@googlegroups.com
On 01/22/2011 04:32 PM, Elijah Insua wrote:
> And I find that I can't use setAttributeNS for things like xml:lang:
>
> > Error
> > at
> /home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:19:11
> > at Object.setAttributeNS
> (/home/rubys/node.js/lib/node/.npm/jsdom/0.1.23/package/lib/jsdom/level2/core.js:233:3)
> > at EventEmitter.do_token
> (/home/rubys/git/xml5/lib.js/parser.js:77:18)
> > at EventEmitter.<anonymous>
> (/home/rubys/git/xml5/lib.js/parser.js:136:30)
> > at EventEmitter.emit (events:31:17)
> > at EventEmitter.emitToken
> (/home/rubys/git/xml5/lib.js/tokenizer.js:85:7)
> > at EventEmitter.emit_current_token
> (/home/rubys/git/xml5/lib.js/tokenizer.js:1536:7)
> > at EventEmitter.empty_tag_state
> (/home/rubys/git/xml5/lib.js/tokenizer.js:1335:8)
> > at EventEmitter.<anonymous>
> (/home/rubys/git/xml5/lib.js/tokenizer.js:72:24)
> > at EventEmitter.emit (events:28:17)
>
> That is a strange error, do you think you could provide a bit more
> information?

How about reproduction instructions? :-)

git clone https://github.com/rubys/xml5.git
cd xml5/lib.js
nodeunit lib.js

> Working around this, I find that I can call createAttributeNode but
> there is no ability provided to call setAttributeNode.
>
> I assume you mean setAttributeNS

I was referring to:

https://developer.mozilla.org/en/DOM/element.setAttributeNode

In any case, if I create an attribute node that is not associated with
an element, what API should I use to add it to an attribute?

> At the moment, I've been monkey-patching:
>
> https://github.com/rubys/xml5/blob/master/lib.js/testrunner.js
>
> But I would like a more sustainable solution.
>
> Agreed, I'm slowly but surely implementing xmlns support in jsdom as of
> HEAD jsdom passes 64% of the DOM level 2 core tests (100 tests failing).

My immediate need is to address those four failing tests. If I can help
in any way, I will try.

> Is there some place to discuss these issues, or should I simply fork
> the project and submit
> pull requests?
>
> Feel free to post here, or raise issues on github. As for patches, I
> readily apply good patches (new code needs to be unit tested).

Will do.

> I'm quite willing, but my preference is for some discussion before I
> dive in as am I am not sure what the best way to,
> for example, disable functionality like automatic uppercasing of
> node names would be.
>
> There is a whole slew of tests in level1/core that ensure that this
> behavior is correct. I'm pretty sure the default is to maintain the
> casing of node names, but I may be mistaken.
> (https://github.com/tmpvar/jsdom/blob/master/lib/jsdom/level1/core.js#L313-323)

The default is maintained internally, but my problem is that when I try
to access it, it is upper cased on the way out. See:

http://intertwingly.net/blog/2011/01/13/xml5-js#c1294948131

> > Error: Cannot find module 'mjsunit.runner/runner'
>
> Ah, just run an `npm install mjsunit.runner` you may also want to
> install htmlparser (`npm install htmlparser`)

Thanks! (It wouldn't hurt to mention that in a README some place)

> I'm new to node.js
>
> Welcome!

Thanks again!

> -- Elijah

- Sam Ruby

Elijah Insua

unread,
Jan 30, 2011, 6:49:45 AM1/30/11
to js...@googlegroups.com
Please forgive the delay in my reply. I have attempted to stay as far away from XML as possible in the past.
 
That is a strange error, do you think you could provide a bit more
information?

How about reproduction instructions?  :-)

git clone https://github.com/rubys/xml5.git
cd xml5/lib.js
nodeunit lib.js
 
hrm, looks like there is still 4 tests failing even though the HEAD of jsdom is only failing 3 tests against the main w3 suite.  We should figure out what is going on here.
 
   Working around this, I find that I can call createAttributeNode but
   there is no ability provided to call setAttributeNode.

I assume you mean setAttributeNS

I was referring to:

https://developer.mozilla.org/en/DOM/element.setAttributeNode

In any case, if I create an attribute node that is not associated with an element, what API should I use to add it to an attribute?

yes. 

var attr = document.createAttributeNodeNS("namespace", "prefix:localName", "value");
someOtherElement.setAttributeNodeNS(attr);
 
   At the moment, I've been monkey-patching:

   https://github.com/rubys/xml5/blob/master/lib.js/testrunner.js

   But I would like a more sustainable solution.

Agreed, I'm slowly but surely implementing xmlns support in jsdom as of
HEAD jsdom passes 64% of the DOM level 2 core tests (100 tests failing).


jsdom is currently at 3 failing tests (level2/core), although I'm not completely satisfied with this status and will be fixing these very soon.

-- Elijah

Sam Ruby

unread,
Jan 30, 2011, 7:38:25 AM1/30/11
to js...@googlegroups.com
On 01/30/2011 06:49 AM, Elijah Insua wrote:
> Please forgive the delay in my reply. I have attempted to stay as far
> away from XML as possible in the past.

No problem.

> That is a strange error, do you think you could provide a bit more
> information?
>
>
> How about reproduction instructions? :-)
>
> git clone https://github.com/rubys/xml5.git
> cd xml5/lib.js
> nodeunit lib.js
>
> hrm, looks like there is still 4 tests failing even though the HEAD of
> jsdom is only failing 3 tests against the main w3 suite. We should
> figure out what is going on here.

I'm running with

export NODE_PATH=/home/rubys/git/jsdom/lib

Additionally, there is a typo in the above that perhaps you caught, it
should be:

nodeunit testrunner.js

I reran the tests, and most of them failed; I took a look at it and one
of my workarounds had to be adjusted. With a simple fix:


https://github.com/rubys/xml5/commit/29e8ebf992e353e2ae43c365c5f94417ce0e0613

... now all of the tests pass again (albeit with workarounds).

> Working around this, I find that I can call
> createAttributeNode but
> there is no ability provided to call setAttributeNode.
>
> I assume you mean setAttributeNS
>
>
> I was referring to:
>
> https://developer.mozilla.org/en/DOM/element.setAttributeNode
>
> In any case, if I create an attribute node that is not associated
> with an element, what API should I use to add it to an attribute?
>
>
> yes.
>
> var attr = document.createAttributeNodeNS("namespace",
> "prefix:localName", "value");
> someOtherElement.setAttributeNodeNS(attr);
>
> At the moment, I've been monkey-patching:
>
> https://github.com/rubys/xml5/blob/master/lib.js/testrunner.js
>
> But I would like a more sustainable solution.
>
> Agreed, I'm slowly but surely implementing xmlns support in
> jsdom as of
> HEAD jsdom passes 64% of the DOM level 2 core tests (100 tests
> failing).
>
>
>
> jsdom is currently at 3 failing tests (level2/core), although I'm not
> completely satisfied with this status and will be fixing these very soon.

Once you are satisfied, perhaps we can work together to eliminate (or at
least reduce) the number of hacks and workarounds I need to apply.

Reply all
Reply to author
Forward
0 new messages