Internet Technologies Week 5 Preliminaries to XML Messaging Introductory Java Threads A multi-threaded server XML Messaging A PowerWarning application.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
Advertisements

Java Server Pages (JSP)
Sockets For Servers Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
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.
Financial Engineering Project Course. Week 7 Java GUI programming and Java Threads GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann.
Internet Technologies1 XML Messaging A PowerWarning application using servlets and SAX The PowerWarning Application is from “XML and Java” by Maruyama,
Internet Technologies 1 Lecture 1 Introduction.
CSE 190: Internet E-Commerce Lecture 7. HTML Templates Designed to separate server side logic from HTML presentation Key features –Escapes from HTML into.
An introduction to Java Servlet Programming
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 10 Object Oriented Programming in Java Advanced Topics Servlets.
1 CS6320 – Servlet Structure and Lifecycle L. Grewe.
Just Java XML Introductory comments Processing XML using XSLT Using XPath Escaping to Java A PowerWarning Application using XML.
OOP/Java1 Introductory Java Threads GUI examples taken from “Computing Concepts with Java 2” by Cay Horstmann Thread examples taken from “The Java.
Servlets. Our Project 3-tier application Develop our own multi-threaded server Socket level communication.
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.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Servlets. - Java technology for Common Gateway Interface (CGI) programming. - It is a Java class that dynamically extends the function of a web server.
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.
J2EE training: 1 Course Material Usage Rules PowerPoint slides for use only in full-semester, for-credit courses at degree-granting.
SKT-SSU IT Training Center Servlet and JSP. Chapter Three: Servlet Basics.
111 Java Servlets Dynamic Web Pages (Program Files) Servlets versus Java Server Pages Implementing Servlets Example: F15 Warranty Registration Tomcat Configuration.
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.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
1 Java and XML Modified from presentation by: Barry Burd Drew University Portions © 2002 Hungry Minds, Inc.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Servlet Lifecycle Lec 28. Servlet Life Cycle  Initialize  Service  Destroy Time.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
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.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
1 JSP with Custom Tags Blake Adams Introduction Advanced Java Server Pages – Custom Tags Keyterms: - Tag Library Descriptor(TLD) - Tag Libraries.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
Servlet Communication Other Servlets, HTML pages, objects shared among servlets on same server Servlets on another server with HTTP request of the other.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
1 Network Programming and Java Sockets. 2 Network Request Result a client, a server, and network Client Server Client machine Server machine Elements.
Chapter 2 Web app architecture. High-level web app architecture  When a client request coming in and needs servlet to serve dynamic web content, what.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Internet Technologies Review Week 1 How does Jigsaw differ from EchoServer.java? What abstractions are made available to the servlet writer (under.
WWW: an Internet application Bill Chu. © Bei-Tseng Chu Aug 2000 WWW Web and HTTP WWW web is an interconnected information servers each server maintains.
Java Servlet API CGI / HTTP Concepts Java Servlet API.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
JavaServer Page by Antonio Ko. Overview ► Introduction ► What is a servlet? ► What can servlets do? ► Servlets Vs JSP ► Syntax ► Samples ► JavaBean ►
Multithreading in JAVA
Java Server Programming Web Interface for Java Programs.
1 CSCD 330 Network Programming Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 9 Client-Server Programming.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Introduction To HTML Dr. Magdi AMER. HTML elements.
How CGI and Java Servlets are Run By David Stein 14 November 2006.
1 Java Programming Java Programming II Concurrent Programming: Threads ( I)
Network Programming: Servers. Agenda l Steps for creating a server Create a ServerSocket object Create a Socket object from ServerSocket Create an input.
Data Communication EDA344, DIT420 Description of Lab 1 and Optional Programming HTTP Assignment Bapi Chatterjee Prajith R G.
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.
1 Introduction SAX. Objectives 2  Simple API for XML  Parsing an XML Document  Parsing Contents  Parsing Attributes  Processing Instructions  Skipped.
USING ANDROID WITH THE INTERNET. Slide 2 Lecture Summary Getting network permissions Working with the HTTP protocol Sending HTTP requests Getting results.
Introduction to Servlets
Threads in Java Two ways to start a thread
Servlet Fudamentals.
Servlet APIs Every servlet must implement javax.servlet.Servlet interface Most servlets implement the interface by extending one of these classes javax.servlet.GenericServlet.
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Introduction to Java Servlets
Servlets Servlets are modules that extend the functionality of a “java-enabled” web-server They normally generate HTML code and web content dynamically.
Presentation transcript:

Internet Technologies Week 5 Preliminaries to XML Messaging Introductory Java Threads A multi-threaded server XML Messaging A PowerWarning application using SAX A DOM example Building a DOM Tree from Scratch Thread examples taken from “The Java Programming Language” By Arnold and Gosling and from Cay Horstmann’s “Core Java 2 Advanced”. The PowerWarning Application is from “XML and Java” by Maruyama, Tamura, and Uramoto, Addison-Wesley.

Internet Technologies Four kinds of thread programming 1) Unrelated threads 2) Related but unsynchronized threads 3) Mutually-exclusive threads 4) Communicating mutually-exclusive threads We will look at the first two (simple) kinds.

Internet Technologies class Coffee extends Thread { Coffee(String name) { super(name); } public void run() { for(int n = 1; n <= 3; n++) { System.out.println("I like coffee"); yield(); System.out.println(this.getName()); yield(); } Unrelated threads

Internet Technologies class Tea extends Thread { Tea(String name) { super(name); } public void run() { for(int n = 1; n <= 3; n++) { System.out.println("I like tea"); yield(); System.out.println(this.getName()); yield(); }

Internet Technologies public class Drinks { public static void main(String args[]) { System.out.println("I am main"); Coffee t1 = new Coffee("Wawa Coffee"); Tea t2 = new Tea(“Sleepy Time Tea"); t1.start(); t2.start(); System.out.println("Main is done"); }

Internet Technologies I am main Main is done I like coffee I like tea Wawa Coffee Sleepy Time Tea I like coffee I like tea Wawa Coffee Sleepy Time Tea I like coffee I like tea Wawa Coffee Sleepy Time Tea Output Main finishes right away Threads are sharing time This program has three threads.

Internet Technologies Using sleep() in unrelated threads The call sleep(millis) puts the currently executing thread to sleep for at least the specified number of milliseconds. "At least“ means there is no guarantee the thread will wake up in exactly the specified time. Other thread scheduling can interfere. Unrelated Threads Part II

Internet Technologies class Coffee extends Thread { Coffee(String name) { super(name); } public void run() { for(int n = 1; n <= 3; n++) { System.out.println("I like coffee"); try { sleep(1000); // 1 second } catch(InterruptedException e) {} System.out.println(this.getName()); }

Internet Technologies class Tea extends Thread { Tea(String name) { super(name); } public void run() { for(int n = 1; n <= 5; n++) { System.out.println("I like tea"); System.out.println(getName()); }

Internet Technologies public class Drinks2 { public static void main(String args[]) { System.out.println("I am main"); Coffee t1 = new Coffee("Wawa Coffee"); Tea t2 = new Tea(“Sleepy Time Tea"); t1.start(); t2.start(); System.out.println("Main is done"); }

Internet Technologies I am main Main is done I like coffee I like tea Sleepy Time Tea I like tea Sleepy Time Tea I like tea Sleepy Time Tea I like tea Sleepy Time Tea I like tea Sleepy Time Tea Wawa Coffee I like coffee Wawa Coffee I like coffee Wawa Coffee 1 second pausing after each “I like coffee” After “I like coffee”, the coffee thread goes to sleep and the tea thread gets to finish and die.

Internet Technologies Yield() and Sleep() Yield() may have no effect on some implementations. The thread scheduler might make no effort toward fairness. The yielding thread may be picked again even though other threads want a turn. It is a good idea to call sleep() instead.

Internet Technologies Ping Pong Adapted from "The Java Programming Language", Arnold and Gosling After a thread is created, you can configure it – set its name, its initial priority (system dependent), and so on. The start() method spawns a new thread of control based on the data in the thread object and then returns. Now, the Java virtual machine invokes the new thread's run method, making the thread active. When a thread's run method returns, the thread has exited. The thread may be manipulated with a number of methods, including the interrupt() method as shown in this example.

Internet Technologies public class PingPong extends Thread { private String word; private int delay; public PingPong(String whatToSay, int delayTime) { word = whatToSay; delay = delayTime; } Each PingPong object knows what to say and how long to sleep.

Internet Technologies public void run() { try { for(;;) { System.out.println(word+" "); sleep(delay); } catch (InterruptedException e) { System.out.println("Interrupted!!!!!"); return; }

Internet Technologies public static void main(String args[]) { PingPong t1 = new PingPong("\tping",33); t1.start(); PingPong t2 = new PingPong("Pong",100); t2.start(); try { Thread.sleep(5000); } catch(InterruptedException e) { // will not be printed System.out.println("Good morning"); return; }

Internet Technologies Thread myThread = Thread.currentThread(); for (int t = 1 ; t <= 10; t++) System.out.println("In Main..." + myThread.getName()); t1.interrupt(); }

Internet Technologies C:\McCarthy\threads\PingPong>java PingPong ping Pong ping Pong ping Pong ping : Main is asleep. For 5 seconds ping and pong take turns sleeping and running

Internet Technologies Pong ping Pong In Main...main Interrupted!!!!! Pong : “Pongs” forever or until until ctrl-c Main wakes up Main interrupts Ping and ping dies.

Internet Technologies A Thread Application --A Simple Web Server Responds by sending the same file on each hit Creates a new thread on each hit

Internet Technologies // A simple multi-threaded web server import java.net.*; import java.io.*; import java.util.*; public class OneFile extends Thread { static String theData = ""; static String contentType; static int contentLength; Socket theConnection;

Internet Technologies // construct each OneFile object with an existing socket public OneFile(Socket s) { theConnection = s; } // run the following code on each object public void run() { try { // get a PrintStream attached to this socket PrintStream os = new PrintStream( theConnection.getOutputStream()); // get a DataInputStream attached to this socket DataInputStream is = new DataInputStream( theConnection.getInputStream()); // read a line from the socket String request = is.readLine();

Internet Technologies // HTTP/1.0 and later send a MIME header if(request.indexOf("HTTP/") != -1) { // we need to read the rest of the MIME header while(true) { String thisLine = is.readLine(); if(thisLine.trim().equals("")) break; } // respond to the client os.print("HTTP/ OK\r\n"); // send the date Date now = new Date(); os.print("Date: " + now + "\r\n"); // send our name os.print("Server: OneFile 1.0\r\n");

Internet Technologies // send the contentLength os.print("Content-length: " + contentLength + "\r\n"); // send the content type os.print("Content-type: " + contentType + "\r\n\r\n"); } // send the file in the string os.println(theData); theConnection.close(); } catch(IOException e) { }

Internet Technologies // main loads the file and creates the object on every hit public static void main(String args[] ) { int thePort; ServerSocket ss; Socket theConnection; FileInputStream theFile; // cache the file try { // open file and create a DataInputStream theFile = new FileInputStream(args[0]); DataInputStream dis = new DataInputStream(theFile);

Internet Technologies // determine the content type of this file if(args[0].endsWith(".html") || args[0].endsWith(".htm") ) { contentType = "text/html"; } else { contentType = "text/plain"; } // read the file into the string theData try { String thisLine; while((thisLine = dis.readLine()) != null) { theData += thisLine + "\n"; } catch(Exception e) { System.err.println("Error " + e); }

Internet Technologies catch(Exception e) { System.err.println(e); System.err.println("usage: java onefile filename port"); System.exit(1); } // set the port to listen on try { thePort = Integer.parseInt(args[1]); if(thePort 65535) thePort = 80; } catch(Exception e) { thePort = 80; }

Internet Technologies // create a server socket try { ss = new ServerSocket(thePort); System.out.println("Accepting connections on port " + ss.getLocalPort()); System.out.println("Data to be sent:"); System.out.println(theData); while(true) { // stop and wait for a connection Socket socketTemp = ss.accept(); // we have a socket so create a handler OneFile fs = new OneFile(socketTemp); // start the handler running fs.start(); } catch(IOException e) {System.out.println("Socket error"); } } Start thread

Internet Technologies 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.

Internet Technologies [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

Internet Technologies 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…

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

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

Internet Technologies XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML XSLT

Internet Technologies 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.

Internet Technologies 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.

Internet Technologies 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);

Internet Technologies 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(); }

Internet Technologies XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML XSLT

Internet Technologies Registrations (HTML) PowerWarning State City Temperature Duration

Internet Technologies 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 .

Internet Technologies 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 {

Internet Technologies 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. */

Internet Technologies 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"));

Internet Technologies /* 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(); }

Internet Technologies PowerWarn.userTable User data Watcher Scheduler Http Request Servlet

Internet Technologies 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(); }

Internet Technologies 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.

Internet Technologies 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 ?

Internet Technologies 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;

Internet Technologies 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; }

Internet Technologies 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);

Internet Technologies 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; }

Internet Technologies /* 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(); }

Internet Technologies /* 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(); }

Internet Technologies 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); } }

Internet Technologies XML Mobile users PC users WeatherReport application WML HTML PowerWarning application Application programs XML notifications Registrations XML

Internet Technologies Building a DOM Tree From Scratch 100 Let’s create this file from within a java program. MyGradeBook.xml

Internet Technologies // DomExample.java // Building an xml document from scratch import java.io.*; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.*; import com.sun.xml.tree.XmlDocument; public class DomExample { private Document document;

Internet Technologies // Get an empty Document object public DomExample () { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try { DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.newDocument(); } catch (Throwable t) { t.printStackTrace (); }

Internet Technologies // Ask the Document object for various types of nodes and // add them to the tree. Element root = document.createElement("GradeBook"); document.appendChild(root); Element student = document.createElement("Student"); root.appendChild(student); Element score = document.createElement("Score"); student.appendChild(score); Text value = document.createTextNode("100"); score.appendChild(value);

Internet Technologies // Write the Document to disk. try { FileOutputStream fos = new FileOutputStream("MyGradeBook.xml"); ((XmlDocument)document).write(fos); } catch(IOException ioe) { ioe.printStackTrace(); } public static void main(String a[]) { DomExample tree = new DomExample(); }