I don't know how the regexp version would work, but here's the code I
currently use to extract the <script> contents from the loaded content when
using my applet based loading.  As it shows below, the "body" variable
contains the complete contents of the code between the <body> tags.

var bodyRE=/<body.*>\n?([\s\S]*)<\/body>/i;
var body=(bodyRE.test(src)) ? bodyRE.exec(src)[1].replace(/\r/,'') : '';
if (src.indexOf("<script")!=-1) {
    var scripts=src.substring(src.indexOf("<script")).split("<script");
    var length=scripts.length;
    if (length>0) {
        for (var i=0; i<length; i++)
scripts[i]=scripts[i].substring(scripts[i].indexOf(">")+1,scripts[i].indexOf("</script>"));

        if (js!=false) for (var i=0; i<length; i++) eval(scripts[i]);
        var body=body.split("/script>");
        var length=body.length;
        for (var i=0; i<length; i++)

body[i]=body[i].substring(body[i].indexOf("/script>")+1,body[i].indexOf("<script"));

        body=body.join("");
    };
};

It should be possible to use the same looping method used in the newer
dragdrop code.

I could't seem to get a regexp version that allowed fr the returning of an
array of results.  If anyone out there knows of a method that works, I'd be
pleased to see it in action.

Richard Bennett wrote:

> Hi,
> I know there's a couple of regexp wizards on the list, I wonder if someone
> can help with this:
>
> It's part of an improved inline-layer code I'm working on (thanks to some
> ideas from Joshua Hewitt) , where all browsers can get the HTML of the
> layer. For NS4 it involves parsing this html out of the body of the
> document.
> I have this working fine now, but am a bit stuck getting the regexps to
> recognize nested <div> tags, what I have so far:
>
> docValue holds the complete html from between the <body> tags:
>
> function getHTML(id,docValue){
>       var re=new RegExp("(<div id=\""+id+"(.*?)<\/div>)","i");
>       var arr = re.exec(docValue)
>       var outer=(arr)?arr[0]:null
>       var re2=new RegExp(">(.*?)</div>")
>       var arr2 = re2.exec(outer)
>       var inner=(arr2)?arr2[1]:null
>       alert(outer)
>       alert(inner)
> }
>
> currently I'm using two steps, first one gets the outer html for a div tag
> with the passed id, second one gets whatever is between ">" and "</div>" -
> the inner html.
> The problem arises when the div contains child divs, is there someway to
> count the amount of "<div" tags, and continue the search until an equal
> amount +1 of "</div>" tags have been matched?
>
> Richard.
>
> _______________________________________________
> Dynapi-Dev mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dynapi-dev

--
Michael Pemberton
[EMAIL PROTECTED]
ICQ: 12107010




_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev

Reply via email to