XML in Web Programming

2008-11-12

Tyng-Ruey Chuang
trc@iis.sinica.edu.tw

Institute of Information Science
Academia Sinica, Taipei, Taiwan

Lecture Outline

We shall study:

We will use these materials in our study:

HTML Forms

Control Types

Here are some of the control types defined in HTML:

buttons
Authors may create three types of buttons: submit buttons, reset buttons, and push buttons.
checkboxes
Checkboxes (and radio buttons) are on/off switches that may be toggled by the user. Several checkboxes in a form may share the same control name.
radio buttons
Radio buttons are like checkboxes except that when several share the same control name, they are mutually exclusive: when one is switched "on", all others with the same name are switched "off".
menus
Menus offer users options from which to choose.
text input
Authors may create two types of controls that allow users to input text. The input element creates a single-line input control and the textarea element creates a multi-line input control.
file select
This control type allows the user to select files so that their contents may be submitted with a form.

HTML Form: An Example

The following HTML markup:

  <form action="http://somesite.com/prog/adduser" method="post">
    <p>
    <label for="firstname">First name: </label>
              <input type="text" id="firstname"/><br/>
    <label for="lastname">Last name: </label>
              <input type="text" id="lastname"/><br/>
    <label for="email">email: </labelL>
              <input type="text" id="email"/><br/>
    <input type="radio" name="sex" value="Male"/>Male<br/>
    <input type="radio" name="sex" value="Female"/>Female<br/>
    <input type="submit" value="Send" /> <input type="reset" />
    </p>
 </form>

describes the following form:




Male
Female

A Form with A textarea Element

The following HTML markup:

<form action="http://somesite.com/prog/text-read" method="post">
   <p>
   <textarea name="thetext" rows="10" cols="40">
   First line of initial text.
   Second line of initial text.
   </textarea>
   <input type="submit" value="Send"/><input type="reset"/>
   </p>
</form>

describes the following form:

Yet Another Form

The following HTML markup:

<form action="http://pomelo.iis.sinica.edu.tw/~trc/play/xslt/transform.php" method="get">
        <p>
	<label>Fetch RSS feed from </label>
	<input type="text" name="site" size="60" value="http://rss.slashdot.org/Slashdot/slashdot"/>.
        <br/>

	<label>Transform the RSS feed into the </label>
  	<select name="xsl">
	<option value="story.xsl"    selected="selected" >full story</option>
	<option value="headline.xsl"                     >headline</option>
	</select> 
        form at the
	<input type="radio" name="method" value="client"/>client side
	<input type="radio" name="method" value="server" checked ="checked"/>server side.<br/>

	<label>Color it </label>
   	<select name="color">
	<option value="blue"  selected="selected" >blue</option>
	<option value="pink"                      >pink</option>
	</select>!<br/><br/>
	
	<input type="submit" value="Do It Now"/>
	</p>
</form>

describes the following form:

.
form at the client side server side.
!

Form Submission

The following request is sent out by the browser:

http://pomelo.iis.sinica.edu.tw/~trc/play/xslt/transform.php?site=http://rss.slashdot.org/Slashdot/slashdot&xsl=story.xsl&method=server&color=blue

when the following HTML form is submitted with the initial values:

<form action="http://pomelo.iis.sinica.edu.tw/~trc/play/xslt/transform.php" method="get">
        <p>
	<label>Fetch RSS feed from </label>
	<input type="text" name="site" size="60" value="http://rss.slashdot.org/Slashdot/slashdot"/>.
        <br/>

	<label>Transform the RSS feed into the </label>
  	<select name="xsl">
	<option value="story.xsl"    selected="selected" >full story</option>
	<option value="headline.xsl"                     >headline</option>
	</select> 
        form at the
	<input type="radio" name="method" value="client"/>client side
	<input type="radio" name="method" value="server" checked ="checked"/>server side.<br/>

	<label>Color it </label>
   	<select name="color">
	<option value="blue"  selected="selected" >blue</option>
	<option value="pink"                      >pink</option>
	</select>!<br/><br/>
	
	<input type="submit" value="Do It Now"/>
	</p>
</form>

You can try it out here:

.
form at the client side server side.
!

The Basics of Web Programming

To use the Web as platform to develop application programs, basically you need to know how to do the following:

XML in Web Programming

Why XML document processing is important in Web programming?

Server-side or Client-side XSLT Processing?

When using XSLT to prepare for the output document in a Web application, we have two choices:

Let's do it both ways!

Example: RSS 1.0 to HTML Transformations

The user provides an RSS 1.0 feed address and specifies how news items in the feed shall be prepared and presented.

RSS 1.0

RSS 1.0 can be thought as RSS 0.93 with namespace support. The following three modules are often used: Dublin Core, Syndication, and Content

The following is a basic RSS 1.0 (0.9-like) document, making use of only the core RSS 1.0 element set.

<?xml version="1.0"?>

<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns="http://purl.org/rss/1.0/"
>

  <channel rdf:about="http://www.xml.com/xml/news.rss">
    <title>XML.com</title>
    <link>http://xml.com/pub</link>
    <description>
      XML.com features a rich mix of information and services 
      for the XML community.
    </description>

    <image rdf:resource="http://xml.com/universal/images/xml_tiny.gif" />

    <items>
      <rdf:Seq>
        <rdf:li resource="http://xml.com/pub/2000/08/09/xslt/xslt.html" />
        <rdf:li resource="http://xml.com/pub/2000/08/09/rdfdb/index.html" />
      </rdf:Seq>
    </items>

    <textinput rdf:resource="http://search.xml.com" />

  </channel>
  
  <image rdf:about="http://xml.com/universal/images/xml_tiny.gif">
    <title>XML.com</title>
    <link>http://www.xml.com</link>
    <url>http://xml.com/universal/images/xml_tiny.gif</url>
  </image>
  
  <item rdf:about="http://xml.com/pub/2000/08/09/xslt/xslt.html">
    <title>Processing Inclusions with XSLT</title>
    <link>http://xml.com/pub/2000/08/09/xslt/xslt.html</link>
    <description>
     Processing document inclusions with general XML tools can be 
     problematic. This article proposes a way of preserving inclusion 
     information through SAX-based processing.
    </description>
  </item>
  
  <item rdf:about="http://xml.com/pub/2000/08/09/rdfdb/index.html">
    <title>Putting RDF to Work</title>
    <link>http://xml.com/pub/2000/08/09/rdfdb/index.html</link>
    <description>
     Tool and API support for the Resource Description Framework 
     is slowly coming of age. Edd Dumbill takes a look at RDFDB, 
     one of the most exciting new RDF toolkits.
    </description>
  </item>

  <textinput rdf:about="http://search.xml.com">
    <title>Search XML.com</title>
    <description>Search XML.com's XML collection</description>
    <name>s</name>
    <link>http://search.xml.com</link>
  </textinput>

</rdf:RDF>

More RSS 1.0 Example

The following is an RSS 1.0 document pulling in elements from various modules (highlighted in different colors). Note: the modules in this example are for illustrative purposes only; refer to RSS 1.0 Modules for consummate module information.

<?xml version="1.0" encoding="utf-8"?> 

<rdf:RDF 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  xmlns:co="http://purl.org/rss/1.0/modules/company/"
  xmlns:ti="http://purl.org/rss/1.0/modules/textinput/"
  xmlns="http://purl.org/rss/1.0/"
> 

  <channel rdf:about="http://meerkat.oreillynet.com/?_fl=rss1.0">
    <title>Meerkat</title>
    <link>http://meerkat.oreillynet.com</link>
    <description>Meerkat: An Open Wire Service</description>

    <dc:publisher>The O'Reilly Network</dc:publisher>
    <dc:creator>Rael Dornfest (mailto:rael@oreilly.com)</dc:creator>
    <dc:rights>Copyright &#169; 2000 O'Reilly &amp; Associates, Inc.</dc:rights>
    <dc:date>2000-01-01T12:00+00:00</dc:date>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>2</sy:updateFrequency>
    <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>

    <image rdf:resource="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg" />

    <items>
      <rdf:Seq>
        <rdf:li resource="http://c.moreover.com/click/here.pl?r123" />
      </rdf:Seq>
    </items>

    <textinput rdf:resource="http://meerkat.oreillynet.com" />

  </channel>

  <image rdf:about="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg">
    <title>Meerkat Powered!</title>
    <url>http://meerkat.oreillynet.com/icons/meerkat-powered.jpg</url>
    <link>http://meerkat.oreillynet.com</link>
  </image>

  <item rdf:about="http://c.moreover.com/click/here.pl?r123">
    <title>XML: A Disruptive Technology</title> 
    <link>http://c.moreover.com/click/here.pl?r123</link>
    <dc:description>
      XML is placing increasingly heavy loads on the existing technical
      infrastructure of the Internet.
    </dc:description>
    <dc:publisher>The O'Reilly Network</dc:publisher>
    <dc:creator>Simon St.Laurent (mailto:simonstl@simonstl.com)</dc:creator>
    <dc:rights>Copyright &#169; 2000 O'Reilly &amp; Associates, Inc.</dc:rights>
    <dc:subject>XML</dc:subject>
    <co:name>XML.com</co:name>
    <co:market>NASDAQ</co:market>
    <co:symbol>XML</co:symbol>
  </item> 

  <textinput rdf:about="http://meerkat.oreillynet.com">
    <title>Search Meerkat</title>
    <description>Search Meerkat's RSS Database...</description>
    <name>s</name>
    <link>http://meerkat.oreillynet.com/</link>
    <ti:function>search</ti:function>
    <ti:inputType>regex</ti:inputType>
  </textinput>

</rdf:RDF>