Tomcat Java and XML. Announcements  Final homework assigned Wednesday  Two week deadline  Will cover servlets + JAXP.

Slides:



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

CSCI N241: Fundamentals of Web Design Copyright ©2004 Department of Computer & Information Science Introducing XHTML: Module B: HTML to XHTML.
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
Parsing XML into programming languages JAXP, DOM, SAX, JDOM/DOM4J, Xerces, Xalan, JAXB.
21-Jun-15 SAX (Abbreviated). 2 XML Parsers SAX and DOM are standards for XML parsers-- program APIs to read and interpret XML files DOM is a W3C standard.
JAX- Java APIs for XML by J. Pearce. Some XML Standards Basic –SAX (sequential access parser) –DOM (random access parser) –XSL (XSLT, XPATH) –DTD Schema.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Introduction to XML Extensible Markup Language
XML Technologies XML Basics  What is XML?  Why use XML?  How to write XML? 1XML Technologies David Raponi.
XML Introduction By Hongming Yu Feb 6 th, Index Markup Language: SGML, HTML, XML An XML example Why is XML important XML introduction XML applications.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Chapter 13 XML Concept of XML Simple Example of XML XML vs. HTML in Syntax XML Structure DTD and CDATA Sections Concept of SAX Processing Download and.
Introducing HTML & XHTML:. Goals  Understand hyperlinking  Understand how tags are formed and used.  Understand HTML as a markup language  Understand.
Chapter 24 XML. CHAPTER GOALS Understanding XML elements and attributes Understanding the concept of an XML parser Being able to read and write XML documents.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
17 Apr 2002 XML Programming: JAXP Andy Clark. Java API for XML Processing Standard Java API for loading, creating, accessing, and transforming XML documents.
XML introduction to Ahmed I. Deeb Dr. Anwar Mousa  presenter  instructor University Of Palestine-2009.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
School of Computing and Management Sciences © Sheffield Hallam University To understand the Oracle XML notes you need to have an understanding of all these.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
XML What is XML? XML v.s. HTML XML Components Well-formed and Valid Document Type Definition (DTD) Extensible Style Language (XSL) SAX and DOM.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
Intro. to XML & XML DB Bun Yue Professor, CS/CIS UHCL.
XML TUTORIAL Portions from w3 schools By Dr. John Abraham.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
XML A web enabled data description language 4/22/2001 By Mark Lawson & Edward Ryan L’Herault.
1 Chapter 10: XML What is XML What is XML Basic Components of XML Basic Components of XML XPath XPath XQuery XQuery.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
XML 2nd EDITION Tutorial 1 Creating An Xml Document.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
Java API for XML Processing (JAXP) Dr. Rebhi S. Baraka Advanced Topics in Information Technology (SICT 4310) Department of Computer.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
1 Introduction  Extensible Markup Language (XML) –Uses tags to describe the structure of a document –Simplifies the process of sharing information –Extensible.
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.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
1 Introduction to XML XML stands for Extensible Markup Language. Because it is extensible, XML has been used to create a wide variety of different markup.
XML Introduction. What is XML? XML stands for eXtensible Markup Language XML stands for eXtensible Markup Language XML is a markup language much like.
1 Tutorial 11 Creating an XML Document Developing a Document for a Cooking Web Site.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML Study-Session: Part III
Java and XML. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information about a document. Tags are added.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
When we create.rtf document apart from saving the actual info the tool saves additional info like start of a paragraph, bold, size of the font.. Etc. This.
What is XML? eXtensible Markup Language eXtensible Markup Language A subset of SGML (Standard Generalized Markup Language) A subset of SGML (Standard Generalized.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Web services. DOM parsing and SOAP.. Summary. ● Exercise: SAX-Based checkInvoice(), ● push parsing, ● event-based parsing, ● traversal order is depth-first.
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.
Introduction to XML Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
XML Introduction to XML Extensible Markup Language.
XML Notes taken from w3schools. What is XML? XML stands for EXtensible Markup Language. XML was designed to store and transport data. XML was designed.
1 Introduction to XML Babak Esfandiari. 2 What is XML? introduced by W3C in 98 Stands for eXtensible Markup Language it is more general than HTML, but.
Extensible Markup Language (XML) Pat Morin COMP 2405.
Unit 4 Representing Web Data: XML
Parsing XML into programming languages
Java XML IS
Java/XML.
Chapter 7 Representing Web Data: XML
Presentation transcript:

Tomcat Java and XML

Announcements  Final homework assigned Wednesday  Two week deadline  Will cover servlets + JAXP

Tomcat Configuration 1. Download the software. Go to 4.0/release/ and download and unpack the zip file for the latest version ( as of last revision of this page). Download the software /release/ 2. Enable the ROOT context. Edit install_dir/conf/server.xml and uncomment this line:. Not necessary in Tomcat and earlier. Enable the ROOT context.

Tomcat Configuration 3. Enable the invoker servlet. Go to install_dir/conf/web.xml and uncomment the servlet-mapping element that maps the invoker servlet to /servlet/*. Not necessary prior to Tomcat Enable the invoker servlet. 4. Change the port to 80. Edit install_dir/conf/server.xml and change the port attribute of the Connector element from 8080 to 80.Change the port to 80.

Tomcat Configuration 5. Turn on servlet reloading. Edit install_dir/conf/server.xml and add a DefaultContext subelement to the main Service element and supply true for the reloadable attribute.Turn on servlet reloading. 6. Set the JAVA_HOME variable. Set it to refer to the base JDK directory, not the bin subdirectory.Set the JAVA_HOME variable.

Servlet example  Goal: Create StudentSort program with web-enable interface?  Ideas?

Outline  What is XML?  JAXP –SAX API –DOM API –XSLT API  JAX-RPC  JAXM  JAXR

Java and XML

XML Basics  Think of XML as a language-neutral text- based way of representing simple objects.  For example, in C: struct Auto{ char* make, char* model, int quantity, double price };

XML Basics, cont  In Java: class Auto{ public String make; public String model; public int quantity; public double price }  Note that C and Java Auto objects are not human- readable, can not be interchanged between languages and platforms (in C case).

XML version of Auto  XML is a formalism for describing simple structures in a language neutral way: <!DOCTYPE Auto [ ]>

XML version of Auto <!DOCTYPE Auto [ ]>

Making Auto objects  In C struct Auto a; a.make = “Ford”; a.model = “Pinto; etc....  In Java Auto a = new Auto(); a.make = “Ford”; etc....

Making auto objects, cont.  XML is not a programming language!  We make a car object in an xml file: Ford Pinto  Think of this as like a serialized java object.

XML vs. DTD  Note that there are two parts to what we did –Defining the “structure” layout –Defining an “instance” of the structure  The first is done with a Document Type Descriptor (DTD)  The second is the XML part  Both can go in the same file, or an XML file can refer to an external DTD file  We will look at the syntax of each

Aspects of XML syntax  It is illegal to omit closing tags  XML tags are case-sensitive  XML elements must be properly nested  XML elements must have a root element  XML preserves whitespaces  XML comments:

DTD syntax  Can be declared either before XML or in separate file as:  Note: DTD’s are not required, but they are strongly recommended for: –ensuring correctness of XML document –standardizing industry-wide layouts

Building blocks of XML  From DTD point of view, XML files are composed of: –Elements –Tags –Attributes –Entities –PCDATA –DATA

Elements  Elements are the fields of the structure, so to speak: –The elements of auto are make, model, price, quantity  Tags are the things that surround (mark-up) elements (...)  Attributes provide extra information about elements –  Entities –characters that are parsed by XML parser. Things like &lt, &gt, &amp, etc.

DTD elements, cont.  PCDATA –Parsed character data. –Text found between the start tag and the end tag of an XML element. –Text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.  CDATA –Character data. –Text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded.

Examples  Study the three simple course examples: –cars.xml –employees.xml –computers.xml  Run the validating parser listed on the course webpage to verify that the xml document is well-formed  See dtd and xml tutorials listed on course website for more cool stuff.

What can we do with this?  So, we have an XML document.  We think of this as a text-based, language neutral serialized object.  But what can we do with it?  How does it relate to html?  Why is it useful?

Displaying XML  Notice that XML documents have no display information  Opening with a browser will show the raw source nicely colored  Display information can be associated with an XML file by using one of two technologies: –CSS (Cascading Style Sheets) Simple, quick –XSL (Extensible Stylesheet Language) made up of XSLT, XPATH, and XSL Formatting Objects Far slicker, more general, and complicated

Displaying XML  We will not study how to display XML in this course  Please see CSS and XSL tutorials listed on course website  Main point is that data is decoupled from display.  Display can be plugged in separately, but data can still be accessed.  Compare computers.html and computers.xml  What is the advantage of computers.xml?

Java and XML  To this point the only special thing about XML is that data and presentation were decoupled, unlike HTML.  The next key feature is language support –Language-neutral standards exists for parsing XML documents! –This means that XML documents are great ways of sharing data between programs, sending messages, etc.

Parsing XML in Java  Two distinct traditional models: –DOM (Document Object Model) –SAX(Simplified API for XML Parsing)  Both are language-neutral standards with bindings specified for Java  These are defined as part of JAXP (Java API for XML Processing)  JDK contains DOM and SAX parser implementations

DOM  DOM represents and XML document in java memory as a tree.  DOM is both read-write  Getting a DOM parser in Java: import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder();

Parsing XML to DOM  Once an instance of the parser is obtained: org.w3c.dom. Document document = builder.parse(xmlFile);  Once a Document object is obtained: org.w3c.dom.Node = document.getDocumentElement(); gets the root Node of the document

Manipulating Nodes  Once the root node is obtained, typical tree methods exist to manipulate other elements: boolean node.hasChildNodes() NodeList node.getChildNodes() Node node.getNextSibling() Node node.getParentNode() String node.getValue(); String node.getName(); String node.getText(); void setNodeValue(String nodeValue); Node insertBefore(Node new, Node ref);

What are Nodes?  Ok, but what information is placed in Nodes? See  Note that the DOM parser parses everthing – white space, tags, comments, etc.  There are several ways to skip over info that doesn’t interest you –use e.g. (if node.getType == Node.TEXT_NODE) –use DocumentBuilderFactory methods to configure parser with comment parsing, etc. turned off.

Node Example  A good practice exercise is to do a depth- first traversal of a Document printing only the element informtion with level- dependent indentation.  I recommend doing this by yourself and then looking at my solution on the web site.  See ScanTree.java

SAX parser  SAX parser scans an xml stream on the fly and responds to certain parsing events as it encounters them.  This is very different than digesting an entire XML document into memory.  Much faster, requires less memory.  However, can not use to change XML.  Need to reparse if you need to revisit data.

Obtaining a SAX parser  Important classes javax.xml.parsers.SAXParserFactory; javax.xml.parsers.SAXParser; javax.xml.parsers.ParserConfigurationException; //get the parser SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); //parse the document saxParser.parse( new File(argv[0]), handler);

DefaultHandler  Note that an event handler has to be passed to the SAX parser.  This must implement the interface org.xml.sax.ContentHanlder;  Easier to extend the adapter org.xml.sax.helpers.DefaultHandler

Overriding Handler methods  Most typical methods to override void startDocument() void endDocument() void startElement(...) void endElement(...) void characters(...)  See examples on course website

Writing XML from DOM import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.Result; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import java.io.File; public class WriteXML{ public static void write(Document doc, String filename) throws Exception { /* Prepare the DOM document for writing */ Source source = new DOMSource(doc); Result result = new StreamResult(new File(filename))); /* Write the DOM document to the file */ Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result);}}

Using JAXP to simplify file input  Goal: read xml-based file into lottery servlet program.

Using JAXP for messaging  Goal: build a socket program that exchanges xml-based messages