Sample Web Application
In our sample application, the user decides on a function to invoke (one of "Factorial," "Fibonacci," "IsPrime" and "nthPrime"), provides the parameter, and clicks on the button corresponding to the desired operation. The basic structure of the code that processes the client input is:
- XmlDocumentObject <-XML document containing the XIM code of the requested computation.
- Get user input parameter and insert it into XmlDocumentObject.
- Insert the processing instruction element to declare the interpreter stylesheet.
- Save the modified document in a file.
- Redirect the client to the saved XML file.
First, the stored "prepackaged" XIM code for the requested computation (whose only missing part is the input parameter value) is loaded into an XmlDocument object and the parameter supplied by the user is inserted into the code at the correct spot. Then the processing instruction indicating the name of the stylesheet (the XIM interpreter) to be applied to the document is inserted into the code. The resulting code in the object is stored in an XML document, and the client browser is redirected to this XML document. To demonstrate what happens when the client supplies a parameter and makes a choice, this code processes a "factorial" request:
private void FactBtn_Click(object sender, System.EventArgs e) { XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load("c://inetpub/wwwroot/xim/fact5.xml"); XmlElement var_n=xmlDoc.CreateElement("var_declare",""); var_n.InnerText=TextBox1.Text; var_n.SetAttribute("name","nb"); // Adding name attribute to variable element // Appending client input as a variable to XIM code // for factorial computation xmlDoc.DocumentElement.FirstChild.AppendChild(var_n); XmlProcessingInstruction newPI; // Processing instruction to declare stylesheet name String PItext = "type='text/xsl' href='interp.xsl'"; // Assigning the name of the interpreter // stylesheet to processing instruction newPI = xmlDoc.CreateProcessingInstruction ("xml-stylesheet", PItext); // Add processing instruction node to the document xmlDoc.InsertBefore(newPI, xmlDoc.DocumentElement); xmlDoc.Save("c://Inetpub/wwwroot/XIM/test.xml"); // Save the modifications to the XIM code // Redirectng the client response // to the just created XIM file Response.Redirect("http://194.27.78.64/XIM/test.xml"); }
See Figure 3 for the result of the interpretation on the client machine of the factorial function, applied to number "20."