Just Java XML Introductory comments Processing XML using XSLT Using XPath Escaping to Java A PowerWarning Application using XML.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

Transforming XML XMLNamespaces, XSLT. XML Namespaces Sometimes it is necessary to mix XML elements –Different types of content –Use of markup to convey.
Internet Technologies1 1 Lecture 4: Programming with XSLT.
1 XSLT – eXtensible Stylesheet Language Transformations Modified Slides from Dr. Sagiv.
XSL XSLT and XPath 11-Apr-17.
+ XSL eXtensible Stylesheet Language. + 2 XML Lecture Adapted from the work of Prof Mark Baker ACET, University of Reading.
XSLT Stylesheets Some more advanced examples (adapted from the Edinburgh LT site)
Objectives Ch. D - 1 At the end of this chapter students will: Know the general architecture and purpose of servlets Understand how to create a basic servlet.
Internet Technologies1 XML Messaging A PowerWarning application using servlets and SAX The PowerWarning Application is from “XML and Java” by Maruyama,
Processing XML Processing XML using XSLT Processing XML documents with Java (DOM) Next week -- Processing XML documents with Java (SAX)
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Internet Technologies XSLT Processing XML using XSLT Using XPath Escaping to Java.
Internet Technologies Week 5 Preliminaries to XML Messaging Introductory Java Threads A multi-threaded server XML Messaging A PowerWarning application.
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Object Oriented Programming III1 XSLT Processing XML using XSLT Using XPath.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Internet Technologies1 XSLT Processing XML using XSLT Using XPath.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
Technical Track Session XML Techie Tools Tim Bornholt.
Java Servlets. What Are Servlets? Basically, a java program that runs on the server Basically, a java program that runs on the server Creates dynamic.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology
XSLT for Data Manipulation By: April Fleming. What We Will Cover The What, Why, When, and How of XSLT What tools you will need to get started A sample.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
XP 1 CREATING AN XML DOCUMENT. XP 2 INTRODUCING XML XML stands for Extensible Markup Language. A markup language specifies the structure and content of.
WORKING WITH XSLT AND XPATH
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language)  XML is a markup language for creating documents containing structured information.
Chapter 5 Java Servlets. Objectives Explain the nature of a servlet and its operation Use the appropriate servlet methods in a web application Code the.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
XML About XML Things to be known Related Technologies XML DOC Structure Exploring XML.
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
Extensible Stylesheet Language Chao-Hsien Chu, Ph.D. School of Information Sciences and Technology The Pennsylvania State University XSL-FO XSLT.
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Transforming Documents „a how-to of transforming xml documents“ Lecture on Walter Kriha.
E0262 – MIS – Multimedia Storage Techniques XML (Extensible Markup Language  XML is a markup language for creating documents containing structured information.
Introduction to XML This presentation covers introductory features of XML. What XML is and what it is not? What does it do? Put different related technologies.
1 Overview of XSL. 2 Outline We will use Roger Costello’s tutorial The purpose of this presentation is  To give a quick overview of XSL  To describe.
Internet Technologies Review Week 1 How does Jigsaw differ from EchoServer.java? What abstractions are made available to the servlet writer (under.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
 XSL – Extensible Style Sheet Language  XSLT – XSL Transformations › Used to transform XML documents to other formats,like HTML or other XML documents.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Introduction To HTML Dr. Magdi AMER. HTML elements.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
7-Mar-16 Simple API XML.  SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files  DOM is a W3C standard  SAX is an.
 XML derives its strength from a variety of supporting technologies.  Structure and data types: When using XML to exchange data among clients, partners,
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Schema – XSLT Week 8 Web site:
1 XSL Transformations (XSLT). 2 XSLT XSLT is a language for transforming XML documents into XHTML documents or to other XML documents. XSLT uses XPath.
Rendering XML Documents ©NIITeXtensible Markup Language/Lesson 5/Slide 1 of 46 Objectives In this session, you will learn to: * Define rendering * Identify.
CH 15 XSL Transformations 1. Objective What is XSL? Overview of XSL transformations Understanding XSL templates Computing the value of a node with xsl:value-of.
1 XSLT XSLT (extensible stylesheet language – transforms ) is another language to process XML documents. Originally intended as a presentation language:
Unit 4 Representing Web Data: XML
Seminar on Service Oriented Architecture
Database Processing with XML
Chapter 7 Representing Web Data: XML
Presentation transcript:

Just Java XML Introductory comments Processing XML using XSLT Using XPath Escaping to Java A PowerWarning Application using XML

Just Java Introduction What is XML? What is XSLT? From XML to HTML using XSLT

Just Java What is XML? XML is an acronym that stands for the eXtensible Markup Language. It is a flexible framework which can be used to create new customized markup languages. HTML, for example, is a markup language with a fixed tag set. …. XML, on the other hand, does not define any particular set of tags. It allows you to create your own tag set.

Just Java What is XML’s primary purpose? Separating data from presentation The range of internet capable devices is growing- WAP phones, pagers, TV sets, web browsers, in car computers, have different presentation requirements. Transmitting data between applications As electronic commerce gathers pace, the amount of data exchanged between organizations is increasing. XML will play a significant role.

Just Java What is XSLT? XSLT stands for eXtensible Style Sheet Language : Transformations XSLT is an XML language for transforming the structure of an XML Document.

Just Java What is XSLT’s primary purpose? With the widespread adoption of XML languages there will be a need to extract and combine data from one set of XML documents to generate another set of XML documents. XSLT In this presentation we will use XSL to convert XML documents to HTML

Just Java When do we use XSLT? (1) The XML document and the associated XSL style sheet may both be transferred to the browser. (2) The server may apply the style sheet to an XML document and the result may be sent to the client. (3) The transformation may occur before the data is placed on the server. Xalan may be used for (2) or (3). IE5 for (1).

Just Java Processing XML using XSLT Visit Sun’s web site for free downloading of Xalan and Xerces. (Xalan is for XSLT and Xerces is an XML parser). The following programs were tested with the command line C:>xalan somefile.xml somefile.xsl resultfile.html The Xalan classes (and xslt processing) may also be accessed via a servlet or Java application.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> Processing

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Output

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> The default rules matches the root, library and block elements.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company The output is the same.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Two books in the input

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> What’s the output?

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Cliff Notes on The Catcher in the Rye Illegal HTML

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> <!-- --> We are not matching on publisher.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company We get the default rule matching the publisher and then printing its child.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company Input

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> We can skip the publisher by matching and stopping the recursion.

Just Java The Catcher in the Rye J. D. Salinger

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company A shelf has many books.

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> Will this do the job?

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company This is not what we want.

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> Found a shelf Checks for a shelf and quits.

Just Java Found a shelf Output

Just Java The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company The Catcher in the Rye J. D. Salinger Little, Brown and Company Same input.

Just Java <xsl:stylesheet xmlns:xsl=" version="1.0"> These are a few of my favorite books Produce a table of books.

Just Java These are a few of my favorite books 1 The Catcher in the Rye J. D. Salinger Little, Brown and Company 2 The XSLT Programmer's Reference Michael Kay Wrox Press 3 Computer Organization and Design Patterson and Henessey Morgan Kaufmann

Just Java

XPATH Non-xml language used to identify particular parts of an xml document Used by XSLT for matching and selecting particular elements to be copied into the result tree. Used by Xpointer to identify a particular point in or part of an xml document that an Xlink links to. Slides adapted from “XML in a Nutshell” by Harold

Just Java XPATH First, we’ll look at three commonly used XSLT instructions: xsl:value-of xsl:template xsl:apply-templates

Just Java XPATH The xsl:value-of element computes the string value of an Xpath expression and inserts it into the result tree. XPath allows us to select nodes in the tree and different node types produce different values.

Just Java XPATH element => the text content of the element after all tags are stripped text => the text of the node attribute => the value of the attribute root => the value of the root processing-instruction => the processing instruction data (, and the target are not included comment => the text of the comment (no comment symbols) namespace => the namespace URI node set => the value of the first node in the set

Just Java XPATH The xsl:template top-level element is the key to all of xslt. The match attribute contains a pattern (location path) against which nodes are compared as they’re processed. If the pattern matches a node, then the contents are instantiated

Just Java XPATH Find and apply the highest priority template that matches the node set expression. If the select attribute is not present then all children of the context node are processed.

Just Java The Tree Structure of an XML Document Alan Turing computer scientist mathematician cryptographer See Harold Pg. 147

Just Java Richard M Feynman physicist Playing the bongoes Unicode ‘M’

Just Java / person born = “1914” died = “1952” id=“p342” person name first_name Alan <!– Did the word “computer scientist” exist in Turing’s day?”-- > profession

Just Java The root Element Nodes Text Nodes Attribute Nodes Comment Nodes Processing Instructions Namespace Nodes Nodes seen by XPath Constructs not seen by XPath CDATA sections Entity references Document Type Declarations

Just Java Note The following appears in each example below so it has been removed from the slides. <xsl:stylesheet xmlns:xsl=" version="1.0" > :

Just Java Location Paths The root matched the root matched the root

Just Java Location Paths Child element location paths (relative to context node) computer scientist

Just Java Location Paths Attribute location paths (relative to context node) 1912

Just Java Location Paths Attribute location paths (relative to context node)

Just Java Location Paths Comment Location Step (comments don’t have names) Did the word "computer scientist" exist in Turing's day?

Just Java Location Paths Comment Location Step comment deleted Document content with comments replaced as shown. Default – no comments output

Just Java Location Paths Text Location Step (Text nodes don’t have names) computer scientist

Just Java Location Paths Processing Instruction Location Step type="text/xsl" href = "pi.xsl"

Just Java Location Paths Wild cards There are three wild cards: *, The * matches any element node. It will not match attributes, text nodes, comments or processing instructions nodes.

Just Java Location Paths Matching with * Matches all elements and requests calls on sub-elements only. Nothing is displayed. The text nodes are never reached.

Just Java Location Paths Matching with node() The node() wild card matches all nodes: element nodes, text nodes, attribute nodes, processing instruction nodes, namespace nodes and comment nodes. Not implemented in XT

Just Java Location Paths Matching wild card matches all attribute nodes. XT does not like it in an but likes it in an

Just Java Location Paths Matching p p4567

Just Java Location Paths Multiple matches with | Matches all the elements. Skips the text nodes unless they describe a profession or hobby.

Just Java Location Paths Selecting from all descendants with // // selects from all descendants of the context node as well as the context node itself. At the beginning of an Xpath expression, it selects from all descendants of the root node.

Just Java Location Paths Selecting from all descendants with // TuringFeynman

Just Java Location Paths Selecting from all descendants with // Alan

Just Java Location Paths Selecting from all descendants with // AlanRichard

Just Java Location Paths Selecting from all descendants with // Richard

Just Java Predicates In general, an Xpath expression may refer to more than one node. Predicates allow us to reduce the number of nodes we are interested in. Each step in a location path may have a predicate that selects from the node list that is current at that step in the expression. The boolean expression in the predicate is tested against each node in the context node list. If the expression is false then that node is deleted from the list.

Just Java Predicates Richard M Feynman

Just Java Predicates Richard M Feynman physicist Playing the bongoes

Just Java Predicates Alan Turing computer scientist mathematician cryptographer

Just Java Predicates Richard M Feynman physicist Playing the bongoes

Just Java Predicates <xsl:apply-templates select = < 1950]/ name[first_name='Alan']" /> Alan Turing

Just Java General XPath Expressions Xpath expressions that are not node sets can’t be used in the match attribute of an xsl:template element. They can be used for the values for the select attribute of xsl:value-of elements and in location path predicates.

Just Java General XPath Expressions

Just Java General XPath Expressions Xpath Functions Person Person 1 Person 2

Just Java General XPath Expressions Xpath Functions Mr. T. Mr. T. Alan Turing Node set converted to string

Just Java Escaping to Java Extension functions provide a mechanism for extending the capabilities of XSLT by escaping into another language Such as Java or JavaScript. If there is no namespace prefix on the function then it must be a core function built into XSLT. Otherwise, it’s an extension function.

Just Java General XPath Expressions Extended Xpath Functions <xsl:template name = "show-date" xmlns:Date = " Using James Clarke’s XT

Just Java Escaping to Java Mon Mar 19 10:46:17 EST 2001

Just Java Escaping to Java // A simple bean saved under Www/beans/MyDate.java // The classpath c:\Jigsaw\Jigsaw\Jigsaw\Www\beans import java.util.*; public class MyDate { Date d; public MyDate() { d = new Date(); } public Date getDate() { return d; }

Just Java public String toString() { return "The date is " + d.toString(); } public static void main(String a[]) { MyDate x = new MyDate(); System.out.println(x); }

Just Java Escaping to Java <xsl:template name = "show-date" xmlns:Date = " The date is Mon Mar 19 11:17:24 EST 2001

Just Java An XML Application XML Messaging A PowerWarning application using XSLT and SAX (Simple API for XML) The PowerWarning Application is from “XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley.

Just Java Example: XML Messaging The PowerWarning application allows users to register their geographical position and their temperature concerns. Users will receive when the temperature exceeds the user specified parameters. This example is from “XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley.

Just Java [1] [2] [3] Weather Report [4] [5] [6] Weather Report -- White Plains, NY [7] [8] Date/Time 11 AM EDT Sat Jul [9] Current Tem. 70° [10] Today’s High 82° [11] Today’s Low 62° [12] [13] [14] Suppose that we know that the weather information is available from the web at

Just Java Strategy 1: For the current temperature of White Plains, go to line 9, column 46 of the page and continue until reaching the next ampersand. Strategy 2: For the current temperature of the White Plains, go to the first tag, then go to the second tag within the table, and then go to the second tag within the row. Neither of these seems very appealing…

Just Java <!DOCTYPE WeatherReport SYSTEM “http>// White Plains NY Sat Jul AM EDT XML would help

Just Java Strategy 3: For the current temperature of White Plains, N.Y., go to the tag.

Just Java XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML XSLT

Just Java The XML Describing the Weather Pittsburgh PA Wed. April 11, This file is behind Jigsaw in the file Www/weather/ weather.xml. Perhaps this is being served up by for ½ cents per hit.

Just Java Serving the weather // This servlet file is stored in Www/Jigsaw/servlet/GetWeather.java // This servlet returns a user selected xml weather file from // the Www/weather directory and returns it to the client. import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class GetWeather extends HttpServlet { This data would not normally be retrieved from a file. It costs ½ cent per hit.

Just Java public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String theData = ""; /* For simplicity we get the user’s request from the path. */ String extraPath = req.getPathInfo(); extraPath = extraPath.substring(1); // read the file try { // open file and create a DataInputStream FileInputStream theFile = new FileInputStream("c:\\Jigsaw\\Jigsaw\\”+ “Jigsaw\\Www\\weather\\"+extraPath);

Just Java InputStreamReader is = new InputStreamReader(theFile); BufferedReader br = new BufferedReader(is); // read the file into the string theData String thisLine; while((thisLine = br.readLine()) != null) { theData += thisLine + "\n"; } catch(Exception e) { System.err.println("Error " + e); } PrintWriter out = res.getWriter(); out.write(theData); System.out.println("Wrote document to client"); out.close(); }

Just Java XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML XSLT

Just Java Registrations (HTML) PowerWarning State City Temperature Duration

Just Java Registrations (Servlet) On servlet initialization, we will start up an object whose responsibility it is to periodically wake up and tell the watcher objects to check the weather. The servlet will create a watcher object for each registered user. The watcher object will be told of each user’s location and temperature requirements. Each watcher object will run in its own thread and may or may not notify its assigned user by .

Just Java Registrations (Servlet) /* This servlet is called by an HTML form. The form passes the user , state, city, temperature and duration. */ import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class PowerWarn extends HttpServlet {

Just Java static Hashtable userTable; /* Holds ( ,watcher) pairs */ public void init(ServletConfig conf) throws ServletException { super.init(conf); PowerWarn.userTable = new Hashtable(); Scheduler scheduler = new Scheduler(); scheduler.start(); /* Run the scheduler */ } /* The scheduler can see the hash table. It has package access. */

Just Java public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { /* Collect data from the HTML form */ String par_user = req.getParameter("User"); String par_state = req.getParameter("State"); String par_city = req.getParameter("City"); int par_temp = Integer.parseInt( req.getParameter("Temperature")); int par_duration = Integer.parseInt( req.getParameter("Duration"));

Just Java /* Assign a watcher to this user. */ Watcher watcher = new Watcher(par_user, par_state, par_city, par_temp, par_duration); /* Place the ( ,watcher) pair in the hash table. */ PowerWarn.userTable.put(par_user, watcher); res.setContentType("text/html"); PrintWriter writer = res.getWriter(); writer.print(" ” + “You'll be notified by "); writer.close(); }

Just Java PowerWarn.userTable User data Watcher Scheduler Http Request Servlet

Just Java The Scheduler import java.util.Enumeration; public class Scheduler extends Thread { public void run() { System.out.println("Running scheduler"); while(true) { Enumeration en = PowerWarn.userTable.elements(); while(en.hasMoreElements()) { Watcher wa = (Watcher)en.nextElement(); new Thread(wa).start(); }

Just Java try { /* put this thread to sleep for 15 seconds */ Thread.sleep(1000 * 15); } catch(InterruptedException ie) { // ignore } } /* end while */ } public Scheduler() { super(); } Fifteen seconds for testing.

Just Java The Watcher Class The Watcher objects make HTTP requests to get XML. SAX. JavaMail. How should we handle the XML? SAX or DOM? How do we send ?

Just Java import org.xml.sax.*; import org.xml.sax.helpers.ParserFactory; import java.io.*; import java.net.*; import org.w3c.dom.Document; import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser;

Just Java public class Watcher extends HandlerBase implements Runnable { String user, state, city; int temp, duration, overTemp; public Watcher(String user, String state, String city, int temp, int duration) { super(); this.user = user; this.state = state; this.city = city; this.temp = temp; this.duration = duration; this.overTemp = 0; }

Just Java public void run() { // called by scheduler System.out.println("Running watcher"); /* Set up to call the weather service. */ String weatheruri = “ “/weather.xml"; /* For simplicity we won’t take the appropriate approach. */ /* String weatheruri = " + URLEncoder.encode(this.city); */ /* Create an InputSource object for the parser to use. */ InputSource is = new InputSource(weatheruri);

Just Java try { /* Set up to handle incoming XML */ SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); SAXParser parser = factory.newSAXParser(); parser.parse(is, this); /* The parser makes the calls. */ } catch(Exception e) { e.printStackTrace(); return; } /* The parsing and callbacks are done by this time. */ int currentTempNumber; try { currentTempNumber = Integer.parseInt(this.currentTemp.trim()); } catch( NumberFormatException e) {e.printStackTrace(); return; }

Just Java /* See if the user wants to be alerted. */ if(currentTempNumber > this.temp) { this.overTemp++; if(this.overTemp >= this.duration) { warning(); } else { this.overTemp = 0; } /* Send via JavaMail. The Mailer class is based on the JavaMail API. */ public void warning() { System.out.println("Sending "); Mailer mailman = new Mailer(this.user, "It's hot"); mailman.send(); }

Just Java /* Handle SAX events. */ StringBuffer buffer; String currentTemp; public void startDocument() throws SAXException { this.currentTemp = null; } public void startElement(String name, AttributeList aMap) throws SAXException { if(name.equals("CurrTemp")) { /* Prepare for next event. */ this.buffer = new StringBuffer(); }

Just Java public void endElement(String name) throws SAXException { if(name.equals("CurrTemp")) { this.currentTemp = this.buffer.toString(); this.buffer = null; } public void characters(char[] ch, int start, int length) throws SAXException { if(this.buffer != null) this.buffer.append(ch,start,length); } }

Just Java XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML