Re: [Xsltforms-support] How to implement http-header pasing on submission?
Brought to you by:
alain-couthures
From: COUTHURES A. <ala...@ag...> - 2010-05-19 21:00:26
|
Hi Kostis, Sorry for the delay, I needed time to analyze this! I understand that a nodeset has to be returned by a event('response-headers') call. The corresponding XSLTForms Javascript function has, then, to return a Javascript array of nodes because it is the way a nodeset is stored in XSLTForms. An XPath expression such as "event('response-headers')[2]" should be possible instead of "event('response-headers')/header[2]" because this one would require a parent-node to be returned instead. I'm not sure that XSLTForms XPath parser would yet accept this and is it valid XPath 1.0 syntax anyway? The only example I found was about insert action: http://en.wikibooks.org/wiki/XForms/Web_Service_Tester. Thank you for your efforts! -Alain > Please, any help on that? > > On Tue, May 11, 2010 at 7:49 PM, Kostis Anagnostopoulos > <ank...@gm...> wrote: > >> Hi Alain, >> >> i saw that you incorporated the event() code i had submitted a while ago, >> so now i'm reworking it, to fix certain issues with it, such as: >> * checking for event-context items case-insesitivly, >> * returning '' when not context items do not exist (insntead of 'undefined'). >> >> Among others, i try to implement the parsing of xml-http-headers, >> as defined by chapter 11.4 [1]. >> >> Therefore, given the 3 response headers below: >> ---------------- >> Date: Tue, 11 May 2010 16:26:46 GMT >> Server: Apache >> Content-Type: text/html; charset=iso-8859-1 >> ---------------- >> >> we should return thw following nodeset: >> ---------------- >> <header xmlns=""> >> <name>Date</name><value>Tue, 11 May 2010 16:26:46 GMT</value >> </header> >> <header xmlns=""> >> <name>Server</name>Apache<value></value >> </header> >> <header xmlns=""> >> <name>Content-Type</name><value>text/html; charset=iso-8859-1</value >> </header> >> ---------------- >> >> >> Based on [2], I crafted the following code to parse the http-headers: >> ---------------- >> /** @headers similar to the headers above */ >> XFSubmission.prototype.parseHttpHeaders_ = function(headers) { >> if (!headers) >> return ''; >> >> var hdoc = new XDocument(); >> var nodes = []; >> try { >> var hlines = headers.split("\r\n"); >> for(var i in hlines) { >> var hline = hlines[i]; >> if (!hline.length) >> continue; >> var hpair = hline.split(":"); >> //alert("name="+hpair[0]+", value="+hpair[1]); >> >> var name = hpair[0]; >> var value = hpair[1].replace("/^\\s*/", ""); >> >> var hel = hdoc.createElementNS("", "header"); >> var nel = hdoc.createElementNS("", "name"); >> var vel = hdoc.createElementNS("", "value"); >> var ntxt = hdoc.createTextNode(name); >> var vtxt = hdoc.createTextNode(value); >> >> nel.appendChild(ntxt); >> vel.appendChild(vtxt); >> >> hel.appendChild(nel); >> hel.appendChild(vel); >> >> hdoc.appendChild(hel);// Is it necessary? >> nodes.push(hel); >> } >> } catch(ex) { >> DebugConsole.write("Error while parsing http-headers: " + ex); >> hdoc = headers; >> } >> >> return hdoc; // should i had returned 'nodes' var instead? >> } >> ---------------- >> >> Now the questions: >> >> 1. Is there i simpler way? >> (ie return an associative array?) >> >> 2) Why the above code does not work when using the XPath expressions below? >> event('response-headers')/header[2]/name >> event('response-headers')/header[1]/value >> ...etc >> >> What should i change with regard to the return value of the >> parseHttpHeaders_() function? >> >> NOTE >> 1. that in the above code i diregarded completely any header-encoding issues, >> and >> 2. that i'm planning to split this function in two, >> one that parses headers to produce an associative array, to be used elsewhere >> (i.e. to decide based on the 'Content-type' whether to parse the >> response-body or not, see [2] again) >> and anotherone, that produces the xml-nodeset. >> >> >> Regards, >> Kostis Anagnostopoulos >> >> >> [1] http://www.w3.org/TR/xforms11/#submit-evt-submit-error >> [2] http://www.w3.org/TR/XMLHttpRequest/ >> >> > > ------------------------------------------------------------------------------ > > _______________________________________________ > Xsltforms-support mailing list > Xsl...@li... > https://lists.sourceforge.net/lists/listinfo/xsltforms-support > > |