Women in Technology

Hear us Roar



Article:
  Exploring E4X with Ruby
Subject:   Nice Idea
Date:   2004-09-12 09:13:40
From:   jherr2002
Response to: Nice Idea

Sounds like you need to add the new tree to the root element as opposed to the document. For example:



myDoc.myRoot << myNewTree;
</code>


As opposed to:



myDoc << myNewTree
</code>


If that doesn't work you can send me (jack_d_herrington@pobox.com) the code and I will take a look at it.

Full Threads Newest First

Showing messages 1 through 4 of 4.

  • Nice Idea
    2004-10-15 12:22:16  HotFusionMan [View]

    I was so happy to see the easy-to-use syntax in this article that I turned the inline code into a library file and a Test::Unit test case. In the course of running the tests, I may have uncovered the bug reported here: the readxml method was not using the document's root to create the NodeWrapper, as the xml method was. Once I added ".root" to the end of the argument to NodeWrapper.new, I had no more test failures.
    • Jack Herrington photo Nice Idea
      2004-10-15 12:41:03  Jack Herrington | O'Reilly Author [View]

      Excellent. Thanks.

      Be advised. I was informed by another reader that because of the operand ordering in Ruby that not all XML structures are available with this code. For example, attributes in namespaces, or attributes which include special characters, like a dash, are not available. Though you can use the standard accessors to get to these.
      • Nice Idea
        2004-10-15 21:36:12  HotFusionMan [View]

        And many thanks to you for the code and article!

        The dash-in-name remark reminds me of something -- I think the same issue arises in the cLabs Internet Explorer Controller (mentioned in one of the files in its distribution if I remember correctly, not directly on its Web pages).

        At least for this case, if the Ruby interpreter required whitespace around the "-" method in calls, that might disambiguate this type of name from the minus operator/method. But I guess that would break the (admittedly rarely seen) syntax foo.-bar or foo.-(bar).
        • Jack Herrington photo Nice Idea
          2004-10-15 21:50:43  Jack Herrington | O'Reilly Author [View]

          Thanks. My pleasure.

          My guess is that outside of a string literal it would be difficult to get Ruby to look at any operator symbol as anything other than just the operator.

          I haven't tried something like this though: foo."-bar"

          I'd try it out but I need some sleep.

          I actually talked with the guys that did the E4X work in Javascript. They did a LOT of work in the tokenizer and lexical analyzer to support the entire XML standard in Javascript.