Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rhino, E4X and xmlns

59 views
Skip to first unread message

David R. MacIver

unread,
Mar 25, 2007, 6:56:58 AM3/25/07
to
If I enter the following piece of E4X into the rhino interpreter:

var page = <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Foo</title>
</head>
<body>
Bar
</body>
</html>


This works fine and I can see that the literal has been assigned to
the variable properly, but I seem to be unable to access the
descendants of page. e.g. if I write

page..head

It just shows a blank line. Presumably that means it's returning null,
undefined, or something similar?

It's the xmlns declaration that seems to be causing it trouble. If I
remove it then I can access the descendants normally.

Am I doing something wrong, or is this a bug?

David

Martin Honnen

unread,
Mar 25, 2007, 8:08:19 AM3/25/07
to
David R. MacIver wrote:
> If I enter the following piece of E4X into the rhino interpreter:
>
> var page = <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <title>Foo</title>
> </head>
> <body>
> Bar
> </body>
> </html>
>
>
> This works fine and I can see that the literal has been assigned to
> the variable properly, but I seem to be unable to access the
> descendants of page. e.g. if I write
>
> page..head
>
> It just shows a blank line. Presumably that means it's returning null,
> undefined, or something similar?

It returns an empty XML list.

The XHTML elements are in a namespace so with E4X you either need to declare

default xml namespace = 'http://www.w3.org/1999/xhtml';

then you can use

page..head

or you need to use a "namespace prefix" e.g.

var xhtml = new Namespace('http://www.w3.org/1999/xhtml');

then you can access

page..xhtml::head


--

Martin Honnen
http://JavaScript.FAQTs.com/

David R. MacIver

unread,
Mar 25, 2007, 8:58:38 AM3/25/07
to

Ah ha, right. I should have thought of that. Thank you.

0 new messages