Sunday, January 29, 2006

E4X to DOM and Back Again

If you're like me, some of the time, you'll work in E4X. Other times, you'll use DOM methods. Occasionally you'll want to switch back and forth from one to the other. Here's how to do the roundtrip.

// create E4X XML object
e4x = <div>Hello World!</div>;

// serialize it
serialzed = e4x.toXMLString();

// create DOM object
dom =
( new DOMParser() ).parseFromString(
serialzed, 'application/xml' );

// make it into a string again
serialized = ( new XMLSerializer() ).serializeToString(dom);

// back to E4X XML object
e4x = new XML( serialized );

Eventually we can expect to see support for a syntax like e4x = new XML( dom ), but this has yet to be implemented in Firefox.



13 comments:

  1. Another work-around for the time being to avoid serializing E4X nodes to a string is to do direct E4X to DOM node translation.

    ReplyDelete
  2. Anonymous2:38 AM

    Ιt's difficult to find experienced people for this topic, but you sound like you know what you'гe tаlking about!
    Τhanκs

    Mу web ρаgе - MintеdPoker Bοnus **

    ReplyDelete
  3. Anonymous5:13 AM

    Hey! I simply would like to give an enormous thumbs up for the good information you’ve right here on
    this post. I will likely be coming back to your weblog for extra
    soon.

    Also visit my blog post ... mini SAS

    ReplyDelete
  4. Anonymous6:40 AM

    I гeаllу like it when people
    come tοgether and shaге opinionѕ.
    Great blog, continue thе good work!

    my blog Treppenlifte Berater

    ReplyDelete
  5. Anonymous5:50 PM

    The best that do floated however is: Dior Skin Abrupt.

    One common online venue to get selling used fashion handbags is ebay.
    Granted that the 1970s rhinestone have remained most valuable
    stream in ones jewelry world. All most of them do is truly replicate the building.
    http://www.devalt-usa.org/content/vacation-resort-paris-build-and-explore-paris-france-all-her-luster

    Here is my page :: chanel glasses

    ReplyDelete
  6. Anonymous6:01 PM

    Hellо аге usіng Wordpгess
    for yоur blog plаtform? I'm new to the blog world but I'm tryіng to get ѕtartеd and create mу оwn.

    Dо уou neеd any сoding expertіѕe to mаke уοur οwn
    blog? Any help woulԁ be rеаlly aρpreciatеd!


    Feel fгее to suгf to mу blog .
    .. comparatif ssd

    ReplyDelete
  7. Anonymous12:10 AM

    Εxcellеnt beat ! ӏ wish to appгentiсe while you amend yοuг wеbѕite, hοw cοulԁ і subѕcribе fοг
    а blog webѕitе? Τhe account aidеd mе a acceptable dеаl.
    I had been a little bit acquainteԁ of this youг broаdcast prονiԁed bright clеаr conceрt

    my ωeb pаge; Just Click The Following Web Page

    ReplyDelete
  8. Anonymous3:39 AM

    Having read this I believed it was very informative. I appreciate
    you finding the time and energy to put this information together.
    I once again find myself spending a lot of time both reading and commenting.
    But so what, it was still worthwhile!

    Here is my homepage - Work From Home

    ReplyDelete
  9. Anonymous5:42 AM

    I've learn a few good stuff here. Certainly value bookmarking for revisiting. I surprise how so much attempt you place to make this kind of magnificent informative website.

    Here is my web site; voyance par telephone

    ReplyDelete
  10. Anonymous6:11 AM

    I’m not that much of a online reader to be honest but your blogs really nice, keep it up!

    I'll go ahead and bookmark your website to come back later on. All the best

    Also visit my homepage - smart phone security issues

    ReplyDelete
  11. Anonymous8:04 PM

    Nowadays, cakes come studded with crystals, have roses falling all over
    the sides, can resemble Christmas trees, and a myriad other
    possibilities. Stick an edible crystal in each diamond point.

    They can be added to any plain cake, whether baked from scratch, made from a cake
    mix or purchased from a shop.

    My web blog; diaper cake ideas and instructions ()

    ReplyDelete
  12. Anonymous11:42 PM

    For example, an actual 3-5 kilowatt water heater might cost $200
    Euros and last longer 20-30 years. Simon Fashion Now is still there on Saturday,
    May 27 at 2 p.m. You should encounter a browse around the
    classic group from Karen Millen. Though the demonstration styles will be pricey (e.
    g. http://zakupator.ru/user.php?login=ramonodd

    ReplyDelete
  13. Anonymous5:17 AM

    Good post. I learn something totally new and challenging
    on blogs I stumbleupon everyday. It will always be helpful to read through
    content from other authors and practice something from other websites.


    Feel free to surf to my page casino bonuses no deposit codes

    ReplyDelete

Please add your comment here!