Writing Enterprise Applications with J2EE (Sixth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Slides:



Advertisements
Similar presentations
XML: Extensible Markup Language
Advertisements

XML and Enterprise Computing. What is XML? Stands for “Extensible Markup Language” –similar to SGML and HTML –document “tags” are used to define content.
XML & Data Structures for the Internet Yingcai Xiao.
XML Parsing Using Java APIs AIP Independence project Fall 2010.
CS 898N – Advanced World Wide Web Technologies Lecture 21: XML Chin-Chih Chang
XML A brief introduction ---by Yongzhu Li. XML --- a brief introduction 2 CSI668 Topics in System Architecture SUNY Albany Computer Science Department.
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
MC365 XML Parsers. Today We Will Cover: An overview of the Java API’s used for XML processing Creating an XML document in Java Parsing an XML document.
CS 898N – Advanced World Wide Web Technologies Lecture 22: Applying XML Chin-Chih Chang
Writing Enterprise Applications with J2EE (Fifth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
XML Technologies and Applications Rajshekhar Sunderraman Department of Computer Science Georgia State University Atlanta, GA 30302
Introduction to XML Extensible Markup Language
COS 381 Day 16. Agenda Assignment 4 posted Due April 1 There was no resubmits of Assignment Capstone Progress report Due March 24 Today we will discuss.
Introducing XHTML: Module B: HTML to XHTML. Goals Understand how XHTML evolved as a language for Web delivery Understand the importance of DTDs Understand.
Technical Track Session XML Techie Tools Tim Bornholt.
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.
Basics of HTML Shashanka Rao. Learning Objectives 1. HTML Overview 2. Head, Body, Title and Meta Elements 3.Heading, Paragraph Elements and Special Characters.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
XP Tutorial 9New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
XP The University of Akron Summit College Business Technology Department Computer Information Systems 2440: 140 Internet Tools Instructor: Enoch E. Damson.
XML Anisha K J Jerrin Thomas. Outline  Introduction  Structure of an XML Page  Well-formed & Valid XML Documents  DTD – Elements, Attributes, Entities.
XML eXtensible Markup Language by Darrell Payne. Experience Logicon / Sterling Federal C, C++, JavaScript/Jscript, Shell Script, Perl XML Training XML.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
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
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Learning Web Design: Chapter 4. HTML  Hypertext Markup Language (HTML)  Uses tags to tell the browser the start and end of a certain kind of formatting.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
What is XML?  XML stands for EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to display data.
Introduction to XML Extensible Markup Language. What is XML XML stands for eXtensible Markup Language. A markup language is used to provide information.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
CITA 330 Section 6 XSLT. Transforming XML Documents to XHTML Documents XSLT is an XML dialect which is declared under namespace "
XSLT Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.
XP Tutorial 9 1 Working with XHTML. XP SGML 2 Standard Generalized Markup Language (SGML) A standard for specifying markup languages. Large, complex standard.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Scripting with the DOM Ellen Pearlman Eileen Mullin Programming the Web.
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.
XP 1 Creating an XML Document Developing an XML Document for the Jazz Warehouse XML Tutorial.
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
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 Design Goals 1.XML must be easily usable over the Internet 2.XML must support a wide variety of applications 3.XML must be compatible with SGML 4.It.
C# and Windows Programming XML Processing. 2 Contents Markup XML DTDs XML Parsers DOM.
XML Study-Session: Part III
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Dom and XSLT Dom – document object model DOM – collection of nodes in a tree.
Computing & Information Sciences Kansas State University Friday, 20 Oct 2006CIS 560: Database System Concepts Lecture 24 of 42 Friday, 20 October 2006.
IT Accessibility Committee XML as Content Management Presented by Michael B. Short May 11, 2006 Prepared by the NYS Forum IT Accessibility Committee
Accessing XML Documents Using DOM ©NIITeXtensible Markup Language/Lesson 8/Slide 1 of 23 Objectives In this lesson, you will learn to: * Use XML DOM objects.
XP Tutorial 9New Perspectives on HTML and XHTML, Comprehensive 1 Working with XHTML Creating a Well-Formed Valid Document Tutorial 9.
Martin Kruliš by Martin Kruliš (v1.1)1.
Tutorial 9 Working with XHTML. New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition 2 Objectives Describe the history and theory of XHTML.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 9 Working with XHTML. XP Objectives Describe the history and theory of XHTML Understand the rules for creating valid XHTML documents Apply a.
XML Extensible Markup Language
I Copyright © 2004, Oracle. All rights reserved. Introduction.
XML Databases Presented By: Pardeep MT15042 Anurag Goel MT15006.
Unit 4 Representing Web Data: XML
XML Related Technologies
XML QUESTIONS AND ANSWERS
XML in Web Technologies
Database Processing with XML
Chapter 7 Representing Web Data: XML
More Sample XML By Sadia Anjum.
Presentation transcript:

Writing Enterprise Applications with J2EE (Sixth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Adding XML to the Mix The example in the previous lessons is modified, so the JavaBean class uses XML APIs to print a simple report where the data is marked with XML tags. We’ll talk about: Marking and Handling Text The XML APIs The required steps for modifying the application are the following: Change the JavaBean Class (page 90) Update and Run the Application (page 96)

Marking and Handling Text (I) With XML you define markup tags to represent the different elements of data in a text file. Once the data is represented by XML tags, you can create a Document Type Definition (DTD) and/or eXtensible Style sheet Language (XSL) file to describe how you want the data handled. XSL styles let you do things like map XML to HTML. For example, you can define an XML title tag to represent the title of an article, and create an XSL file that maps the XML title tag to the HTML H1 heading tag for display to the end user. A DTD (also known as an XML schema) contains specifications that allow other programs to validate the structure of an XML file to ensure the tagged data is in the correct format. Checking an XML document against a DTD is what is known as verification.

Marking and Handling Text (II) An interesting characteristic of XML is the separation of tagging from the style sheet and DTD. This means that you can have one single XML document and one to many style sheets or DTDs. Different style sheets let you have a different presentation depending on how the document is used. For example, an article on XML can have a style sheet for the different web sites where it is to be published so it will blend with the look and feel of each site. The current J2EE release does not have an eXtensible Style sheet Language Transformation (XSLT) engine so it is not currently possible to use a style sheet to do things such as transform an XML document into HTML for display.

Change the JavaBean Class Our goal is the modification of the JBonusBean class, inserting a genXML method to generate the XML document shown below. Before the analysis of the source code, a brief discussion of the main issues is presented.

XML Prolog The line is the XML prolog. It’s aimed at identifying the document as an XML file. The prolog is not required and is read only by humans, but it is good form to include it. Besides version information, the prolog can also contain encoding and standalone information. Encoding information: indicates the character set used to encode the document data. Uncompressed Unicode is shown as. The Western European and English language character set is indicated by:. Standalone information: indicates if this document uses information in other files. For example, an XML document might rely on a style sheet for information on how to create the user interface in HTML, or a DTD for valid tag specifications..

Document Root The tag is the first XML tag in this file. It is the top-level XML tag and marks the beginning of the document data. Another name for this level tag is root. XML tags have a matching end tag, so the end of this document has the corresponding tag to close the pair. You can give XML tags any name you want. This example uses report because the XML file is a bonus report. It could just as well be named or or whatever. The name takes on meaning in the style sheet and DTD because that is where you assign specifications to tags by their names.

Child Nodes The tag represents the bonus report. This tag is a child node that is added to the root. It uses attributes to specify the social security number and bonus amount values (ssnum and bonusAmt ). You can define a DTD to check that the bonusCalc tag has the ssnum attribute and bonusAmt attributes, and have your program raise an error if an attribute is missing or if attributes are present that should not be there.

JavaBean Code (I) The current JBonusBean class has import statements for creating the XML document, handling errors, and writing the document out to the terminal. The XML output is sent to the terminal to keep things simple. The XML output could just as well be written to a file, but you would need to configure your browser to use Java Plug-In and include a security policy file granting the JavaBean code permission to write to the file. To generate the XML file, you need to import the ElementNode and XmlDocument. StringWriter and IOException are used to write the XML data to the terminal. import javax.naming.*; import javax.rmi.PortableRemoteObject; import Beans.*; import java.io.StringWriter; import java.io.IOException; import com.sun.xml.tree.ElementNode; import com.sun.xml.tree.XmlDocument;

JavaBean Code (II) The session bean’s remote interface, theCalculation, needs to be accessed from the getBonusAmt and genXML methods. This is because genXML reads the database to generate XML for all records stored in the database and has to be able to access the session bean’s getRecord method. JBonusBean.genXML is called from the getBonusAmt method after the processing completes in the event strMult is not null. The first thing this method does is create an XMLDocument object and the root node, and adds the root to the document. The root node is the point at which processing begins. private void genXML(){ Bonus records = null; //Create XML document XmlDocument doc = new XmlDocument(); //Create node ElementNode root = (ElementNode) doc.createElement("report"); //Add node to XML document doc.appendChild(root);

JavaBean Code (III) The next try and catch block gets the record out of the database, retrieves the bonus amount and social security number from the record, creates a child node ( bonusCalc ), and adds the social security number and bonus amount to the bonusCalc child node as attributes. The child node represents the second level in the document hierarchy or tree, and the attributes represent the third level. try{ //Get database record records = theCalculation.getRecord(socsec); //Retrieve the social security number from record String ssRetrieved = records.getSocSec(); //Retrieve bonus amount from record double bRetrieved = records.getBonus(); Double bonusObj = new Double(bRetrieved); String bString = bonusObj.toString(); //Create child node ElementNode bonusCalc = (ElementNode) doc.createElement("bonusCalc"); bonusCalc.setAttribute("ssnum", ssRetrieved); bonusCalc.setAttribute("bonusAmt", bString); //Add child node to root root.appendChild(bonusCalc); } catch (java.rmi.RemoteException e) { e.printStackTrace(); }

JavaBean Code (IV) The last part of genXML creates a StringWriter object, writes the document hierarchy to the StringWriter object, and writes the StringWriter object to the terminal. The API calls in genXML create the DOM; a DOM can be created also from an XML file. try{ StringWriter out = new StringWriter(); doc.write(out); System.out.println(out); } catch (java.io.FileNotFoundException fe) { System.out.println("Cannot write XML"); } catch (IOException ioe) { System.out.println("cannot write XML"); }

The XML APIs The j2ee.jar file provides APIs for parsing and manipulating XML data. The JAR file currently provides SAX, DOM, and J2EE XML APIs. You can use whichever API best suits your needs. Constructing the DOM requires reading the entire XML structure and holding the object tree in memory, so it is much more CPU and memory intensive. For that reason, the SAX API will tend to be preferred for server-side applications and data filters that do not require an in-memory representation of the data. The platform-independent J2EE XML APIs use a DOM tree and provide a wealth of methods for manipulating the DOM hierarchy. The J2EE XML APIs are in the package com.sun and were used in the previous example. Please note that these APIs are subject to change.