Permalink
Browse files

adding form to table convertor

  • Loading branch information...
1 parent b0c7e32 commit 830e1b9af9c5a8a2319a2e53b7f26c7e67b46eeb @sh1mmer sh1mmer committed Mar 4, 2010
Showing with 110 additions and 0 deletions.
  1. +110 −0 misc/misc.forms2tables.xml
View
110 misc/misc.forms2tables.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <author>Tom Hughes-Croucher (croucher@yahoo-inc.com)</author>
+ <sampleQuery></sampleQuery>
+ </meta>
+ <bindings>
+ <select itemPath="" produces="XML">
+ <urls>
+ <url></url>
+ </urls>
+ <inputs>
+ <key id='url' type='xs:string' paramType='variable' required="true" />
+ <key id='xpath' type='xs:string' paramType='variable' required="true" />
+ <key id='author' type='xs:string' paramType='variable' required="false" />
+ </inputs>
+ <execute><![CDATA[
+
+ var script = "";
+
+ var myq = "select * from html where url = '" + url + "' and xpath = '" + xpath + "'";
+
+ page = y.query(myq).results;
+
+ method = page.form.@method;
+
+ if (method == "get" || method == "GET") {
+ keyType = "query";
+ } else {
+ keyType = "variable";
+ }
+
+ action = page.form.@action;
+
+ default xml namespace = "http://query.yahooapis.com/v1/schema/table.xsd";
+ table = <table xmlns="http://query.yahooapis.com/v1/schema/table.xsd"><meta><documentationURL>{url}</documentationURL></meta><bindings><select itemPath="" produces="XML"><urls><url>{action}</url></urls><inputs /></select></bindings></table>;
+
+ if (author) {
+ table.meta.node += <author>{author}</author>;
+ }
+
+ //reset the namespace to select the input elements
+ default xml namespace = "";
+ for each(var input in page..input) {
+
+ //reset the namespace to get info from input element
+ default xml namespace = "";
+ var type = input.@type;
+ var name = input.@name;
+ var value = input.@value;
+
+
+
+ if (( type == "hidden" || type == "submit" ) && name.toString() != "" && value.toString() != "") {
+
+ default xml namespace = "http://query.yahooapis.com/v1/schema/table.xsd";
+ table.bindings.select.inputs.node += <key id={name} type="xs:string" paramType={keyType} const="true" default={value} />;
+
+ } else if (name.toString() != "") {
+ default xml namespace = "http://query.yahooapis.com/v1/schema/table.xsd";
+ var name = input.@name;
+
+ table.bindings.select.inputs.node += <key id={name} type="xs:string" paramType={keyType} required="false" />;
+ }
+
+ }
+
+ //reset the namespace to select the input elements
+ default xml namespace = "";
+ for each(var select in page..select) {
+
+ //reset the namespace to get info from input element
+ default xml namespace = "";
+ var type = select.@type;
+ var name = select.@name;
+
+ if (name.toString() != "") {
+ default xml namespace = "http://query.yahooapis.com/v1/schema/table.xsd";
+ var name = select.@name;
+
+ table.bindings.select.inputs.node += <key id={name} type="xs:string" paramType={keyType} required="false" />;
+
+ var conditionals = [];
+ var options = [];
+ default xml namespace = "";
+ for each (var option in select.option) {
+ conditionals.push(name + ' == "' + option + '"');
+ options.push(option);
+ }
+ var conditional = "if (!(" + conditionals.join(" || ") + " || " + name + " == '')) { throw '" + name + " must be one of the following values: " + options.join(", ") + "';}";
+ script += conditional;
+
+ }
+ }
+
+ if (method == "get" || method == "GET") {
+
+ default xml namespace = "http://query.yahooapis.com/v1/schema/table.xsd";
+ script += "output = y.query(\"select * from html where url='" + url + "'\").results; response.object = output;";
+ script = "\<\!\[CDATA\[" + script + "\]\]\>";
+ execute = <execute>{script}</execute>
+ table.bindings.select.node += execute;
+ }
+
+ response.object = table;
+
+ ]]></execute>
+ </select>
+ </bindings>
+</table>

0 comments on commit 830e1b9

Please sign in to comment.