[Greasemonkey] e4x

Mor Roses moroses at gmail.com
Sun Feb 12 18:42:43 EST 2006


I got bored at home so i made you a function for importing XML string into a
document usage:
node=importNode(<p id="test"><a href="http://www.google.com">Click
me</a></p>,document)
element.appendChild(node);

the function:

function importNode(xmlObj,doc) {
    var me=arguments.callee;
    var xhtmlObj=<testing xmlns={me.Const.xhtmlns} />;
    if(!me.Static.parser) me.Static.parser=new me.Const.parseObject;
    xhtmlObj.test=xmlObj;
    var domTree=me.Static.parser[me.Const.parseFunction](
xhtmlObj.toXMLString(),me.Const.mimeType);
    var importMe=domTree.documentElement.firstChild;
    while(importMe && importMe.nodeType!=1) importMe=importMe.nextSibling;
    return (importMe)?doc.importNode(importMe,true):null;
}

importNode.Const={
    'xhtmlns' : "http://www.w3.org/1999/xhtml",
    'mimeType' : "text/xml",
    'parseObject' : DOMParser,
    'parseFunction' : 'parseFromString'
};

importNode.Static={};

On 2/10/06, Stéphane Payrard <stef at stefp.dyndns.org> wrote:
>
> Mook a écrit :
> <snip>
> | <link-spam>
> | I'm using e4x as a hack to get multiline strings in greasemonkey -
> | that might be useful to someone :)  After all, JS hasn't got
> | HEREDOC...
> |
> | </link-spam>
>
> I wish all spam would be like that.
> In your example, I see that when one creates a XML string, he has
> to wrap it in a extra element, here denoted by <r>...</r>.
> How strange, I have noted the same behavior on my (not yet
> greasemonkey) e4x scripts.
>
> Also, I am able to insert such "XML string" using xmlstr.innerHTML but
> not using document.appendChild(xmlstr).  I am not sure what is the
> proper way to do it.
>
> If one can point me to some greasemonkey scripts using e4x, I am sure
> I could pick some good idioms,
>
> Disclaimer : I have not gone thru the e4x spec
>
> Thx Mook.
> Thx for all explanations and advices from people on that thread.
>
>
> |
> | --
> | Mook
>
> --
>   cognominal stef
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list