E4X/Firefox 1.5: problem using default xml namespace

B

Bob Tinsman

I've been interested in E4X because my company has an XML schema that
we usually manipulate through a Java mapping generated by Castor, which
I think is fairly tedious, and which means you have to do everything in
the webapp. I think it'd be cool to suck in the XML, tweak it in the
browser, then use a SOAP call to submit it to the server.

Anyhow, we use namespaces on all our elements, and I was trying to
avoid using the "ns::elementname" notation if I didn't have to. I
thought that calling "default xml namespace = 'our.namespace'" would
let us do that. In other words, I could do something like this:

var a = <n:abc
xmlns:n="urn:something"><n:foo>1</n:foo><n:foo>2</n:foo></n:abc>;
default xml namespace = "urn:something";
alert(a.foo);

However, running that inside a function in a web page returns an empty
string. But the following:

alert(eval("a.foo"));

returns what I expect, which is this:

<n:foo xmlns:n="urn:something">1</n:foo>
<n:foo xmlns:n="urn:something">2</n:foo>

I tried an example with both of these:

alert(a.foo);
alert(eval("a.foo"));

But if they are in the same method, "a.foo" returns the same thing as
"eval('a.foo')", which is mighty strange. Even if I do:
alert(a.foo);
eval("");

I get it to work. That tells me there is something about the parsing of
the expression that is going awry, but the presence of the eval("")
makes it work OK.

My Mozilla version is: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1

I tried Rhino 1.6R2 and I get the behavior I expect, with the eval or
not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top