E4X/Firefox 1.5: problem using default xml namespace

Discussion in 'Javascript' started by Bob Tinsman, Mar 14, 2006.

  1. Bob Tinsman

    Bob Tinsman Guest

    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.
    Bob Tinsman, Mar 14, 2006
    #1
    1. Advertising

  2. Bob Tinsman wrote:

    > 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);


    The problem seems only to occur if that code is executed in function
    scope. Nevertheless it is a bug in my understanding so I have filed a
    bug report
    <https://bugzilla.mozilla.org/show_bug.cgi?id=330572>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Mar 15, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joris Gillis
    Replies:
    2
    Views:
    1,533
    Joris Gillis
    Jun 16, 2006
  2. Daniel Berger

    [ARTICLE] E4X with Ruby

    Daniel Berger, Sep 11, 2004, in forum: Ruby
    Replies:
    4
    Views:
    126
    Erik Terpstra
    Sep 13, 2004
  3. Bob Tinsman

    E4X: can't use "delete" with filter

    Bob Tinsman, Mar 14, 2006, in forum: Javascript
    Replies:
    2
    Views:
    78
    Martin Honnen
    Mar 15, 2006
  4. Replies:
    4
    Views:
    134
    Martin Honnen
    Apr 23, 2006
  5. ten8ciousb
    Replies:
    7
    Views:
    137
    Thomas 'PointedEars' Lahn
    Jan 26, 2009
Loading...

Share This Page