Return-Path: Delivered-To: apmail-xml-cocoon-users-archive@xml.apache.org Received: (qmail 24400 invoked by uid 500); 25 Nov 2002 13:30:21 -0000 Mailing-List: contact cocoon-users-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-users@xml.apache.org Delivered-To: mailing list cocoon-users@xml.apache.org Received: (qmail 24389 invoked from network); 25 Nov 2002 13:30:21 -0000 Message-ID: <20021125133020.86453.qmail@web40806.mail.yahoo.com> Date: Mon, 25 Nov 2002 05:30:20 -0800 (PST) From: Geoff Howard Subject: Re: JavaScript problems in XSP To: cocoon-users@xml.apache.org In-Reply-To: <003b01c29459$cefecb00$a800000a@lisa> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Aha. For future reference, you probably should have made it clear from the beginning that you were a) using javascript xsp, and b) trying to do this specific thing with retrieving external pages out of your control. That said, you are probably in uncharted waters - but interesting ones. The first thing I'd try is make sure that this ability doesn't already exist by some miracle in JTidy or another html parser. I'd suggest trying the following (but you have to promise to let me know whether it works or not). What about tricking the client side javascript into evaluating the document.write and document.writeln? For instance, set up a javascript object called "document" which initializes an empty text holder and exposes a write() and writeln() method to append to that variable. Then, use eval() on each line taken out of your script tags. So, function write(string) {this.text += string;} function writeln(string) {this.text += (string + '\n')}; function doc() { this.text=""; this.write = write; this.writeln = writeln; } then when you encounter a script section do something like: var document = new doc(); eval('document.writeln...); eval('document.write...); document.text where you take each string to eval out of the incoming script section, probably in a for loop. any other variables and operations it uses to prepare values should work the same as normal. You'll have trouble with escaping quotes, and extracting the strings but it may be possible. Other than that, I'm out of ideas. You may not be able to do this at all in a way that is worth the effort. Geoff --- Anna Afonchenko wrote: > I am not using document.write. > What I am trying to do is load some arbitrary file > from the net (not my > file, just any file, so I don't have control on > what's written inside) and > if this file contains script tag (which is written, > for example, in > Javascript), I want to extract the HTML tree > fragment that is generated by > this (Java)script. > I use xsp to include the given file, that's all, > then I use xsl to extract > the data inside the script tags. But what I get is > again the script code, > e.g. > document.write("
Hello
"); > > What I'm asking is whether it's possible to extract > the HTML that the script > is writing - in this case it's just to get the value > of the document.write > method, but it can be something more complicated. > I don't know if this can be done at all, in > Cocoon/XSP/XSL. > If somebody will have any idea how to do it, I will > be very thankful. > Sorry if this is too messy, I am new to this list > and to cocoon at all. > Thank you for all the help. > > Anna > ----- Original Message ----- > From: "Geoff Howard" > To: > Sent: Sunday, November 24, 2002 4:54 PM > Subject: Re: JavaScript problems in XSP > > > Why are you using document.write? document of > course > is a reference to the client side document object > which doesn't exist server side at all. > > The problem with your example is that you don't need > javascript (or xsp for that matter) to do any of > that. > Obviously you want to move beyond that though. > It's > also unclear whether you want that fragment to be > included in the sax stream, or whether you want that > output escaped and displayed as is on screen (i > think > the first). > > I'm not sure you can (using javascript in xsp) > easily > take an xml fragment in string form and generate sax > events from it. It doesn't matter though because > you > probably really don't need to. What you should > probably do is start with (note the ... implies that > you probably have other page structure but you don't > need to for this example) > > xmlns:xsp="http://apache.org/xsp"> > ... >
> > This HTML-document has been created with the > help of JavaScript! > >
> ... >
> > And then use > etc to make whatever parts dynamic. > > For example, a next step might be : > > xmlns:xsp="http://apache.org/xsp"> > ... > > message = "This HTML-document has been created with > the > help of JavaScript!"; > >
> > message > >
> ... >
> > and then, > > xmlns:xsp="http://apache.org/xsp"> > ... > > message = "This HTML-document has been created with > the > help of JavaScript!"; > displayMessage = true; > > ... > > if (displayMessage) { >
> > message > >
> } >
> ... >
> > > The best place I know of to read up on the xsp sytax > is > http://outerthought.net/wiki/Wiki.jsp?page=XSPSyntax > as the official docs don't catalog the available > tags > IIRC. > > If you don't mind me saying so, I'd also suggest > that > you read up some more on the basic ideas behind the > cocoon sax pipeline concept and what generators do > as > it seems you may have some of the concepts muddled. > XSP is only a tool for automatically creating a > generator - a compiled java class no matter what > language you script your xsp in. > > Best of luck, > Geoff Howard > > --- Anna Afonchenko wrote: > > Thank you Ryan. Now what I get when I run the > > pipeline, what I see is the > > result of running the javascript. But what I > really > > need is the "source" of > > this javascript, e.g. if the javascript code was: > > document.write("
"); > > document.write("This HTML-document has been > created > > "); > > document.write("with the help of JavaScript!"); > > document.write("
"); > > > > I want to get as a result the xhtml tree fragment > > that is created, e.g. I > > want to get back: > >
> > > > This HTML-document has been created with > the > > help of JavaScript! > > > >
> > > > e.g. I want to see the actual HTML code that was > > used in javascript to > > create the given page, and not the result of > > executing it. > > > > Is it doable in Cocoon/XSP? > > Thank you very much for your help. > > > > Anna > > > > ----- Original Message ----- > > From: "Ryan Agler" > > To: > > Sent: Thursday, November 21, 2002 4:26 PM > > Subject: RE: JavaScript problems in XSP > > > > > > Hi Anna, > > Client-side (in your web browser) JavaScript is a > > completely different > > beast than server-side (on your web server) > > JavaScript. In server-side > > JavaScript, there are no windows, DHTML, or much > any > > other properties or > > methods you would use to manipulate a browser for > > dynamic content. > > > > To use Cocoon to achieve your task, the first step > > would to define > > "given-file.html" in your sitemap, and make sure > its > > serialized in > > well-formed XHTML. Then you could use the > Cinclude > > transformer to > > import given-file.html, kind of like this > > (myfile.xsp): > > > > > > > xmlns:xsp=http://apache.org/xsp> > > > > xmlns:cinclude="http://apache.org/cocoon/include/1.0"> > >

> > > src="cocoon:/given-file.html" /> > >

> >
> >
> > > > and in your sitemap.xmap: > > > > > > > src="docs/given-file.xsp" /> > > /> > > > > > > > > > > > src="docs/myfile.xsp" /> > > > > > > > > > > > > HTH > > > > +Ryan > > > > -----Original Message----- > > From: Anna Afonchenko [mailto:anna@ubaccess.com] > > Sent: Thursday, November 21, 2002 7:43 AM > > To: cocoon-users@xml.apache.org > > Subject: Javascript problems in XSP > > > > Hi All. > > This is my first post, so don't be angry with me > if > > I do something > > wrong. > > I am using XSP on Cocoon 2.0.3, and I want to do > the > > following: > > given a name of the html file that contains > > javascript, I want to get > > the result of this javascript and > > put it inside some element in XSP. But when I > write > > the following code > > in XSP using javascript: > >

> > > > var js = window.open("given-file.html"); > > var result = js.document.body.innerHTML; > > > > result > >

> > > > nothing happens (even doesn't give any error). > > If I am using this code inside an html file's > script > > tag, it works fine. > > If I am trying some simple Javascript functions in > > XSP (e.g. Date()), it > > works. > > Maybe there is some problem with opening files in > > XSP? > > > > Can somebody please tell me what am I doing wrong > > and how can I get the > > result of javascript code executed in some given > > file? > > > > Thank you very much in advance. > > > > Anna > > > > > --------------------------------------------------------------------- > > Please check that your question has not already > > been answered in the > > FAQ before posting. > > > > > > To unsubscribe, e-mail: > > > > For additional commands, e-mail: > > > > > > > > > --------------------------------------------------------------------- > > Please check that your question has not already > > been answered in the > > FAQ before posting. > > > > > > To unsubscribe, e-mail: > > > > For additional commands, e-mail: > > > > > > > __________________________________________________ > Do you Yahoo!? > Yahoo! Mail Plus - Powerful. Affordable. Sign up > now. > http://mailplus.yahoo.com > > --------------------------------------------------------------------- > Please check that your question has not already > been answered in the > FAQ before posting. > > > To unsubscribe, e-mail: > > For additional commands, e-mail: > > > > --------------------------------------------------------------------- > Please check that your question has not already > been answered in the > FAQ before posting. > > > To unsubscribe, e-mail: > > For additional commands, e-mail: > > __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus � Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. To unsubscribe, e-mail: For additional commands, e-mail: