Hi Geoff. Thank you for your help, I appreciate this very much. I tried the code that you suggested, and I have a few questions/issues: 1. First of all I tried to give the eval() function some simple string that I declared inside the <xsp:logic> tag: someStr = "document.write('<center>Hello</center>')"; If I write this string inside the <xsp:expr>document.text</xsp:expr>, the output is:
<?xml version="1.0" encoding="UTF-8" ?> <page xmlns:xsp="http://apache.org/xsp" xmlns:xsp-request="http://apache.org/xsp/request/2.0" xmlns:util="http://apache.org/xsp/util/2.0"> <p><center>Hello</center></p> </page> which is great, but when I looked in the source code, I found out that the <center>Hello</center> string is written using entities, e.g. it is not a node-set of the output xml document. Trying to enclose the <xsp:expr> tag inside the <util:include-expr> tag: <util:include-expr><util:expr><xsp:expr>document.text</xsp:expr></util:expr> </util:include-expr> the surprising output is: <?xml version="1.0" encoding="UTF-8" ?> <page xmlns:xsp="http://apache.org/xsp" xmlns:xsp-request="http://apache.org/xsp/request/2.0" xmlns:util="http://apache.org/xsp/util/2.0"> <p> <util:include-expr> <util:expr><center>Hello</center></util:expr> </util:include-expr> </p> </page> i.e. <center>Hello</center> remains to be a string and not a node-set, but now it is enclosed in a tree fragment <util:include-expr><util:expr>. This is strange. Do you have any idea how can I avoid outputting the result as a string (with entities) rather that outputting it as a node-set? 2. How can I retrieve the content of some html file from xsp with javascript? And parse it? When I was using Java inside an xsp, i could write the following: XSPUtil u = new XSPUtil(); String get = u.getFileContents(URL of the file); Can I do something like this from Javascript? I tried: content = <util:get-file-contents name="URL of the file">; but it doesn't work. Is it possible that there are problem using util library from xsp with javascript? Thank you for your help. I will wait for your answer. I hope this is not too long. Grateful Anna ----- Original Message ----- From: "Geoff Howard" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, November 25, 2002 3:30 PM Subject: Re: JavaScript problems in XSP 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: <xsp:logic> var document = new doc(); eval('document.writeln...); eval('document.write...); </xsp:logic> <xsp:expr>document.text</xsp:expr> 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 __________________________________________________ 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. <http://xml.apache.org/cocoon/faq/index.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]> --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>