1 XML and Web App 1. Objectives 2  Building Database-Driven Applications  Building Data Exchange Applications  Workshops.

Slides:



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

DOCUMENT TYPES. Digital Documents Converting documents to an electronic format will preserve those documents, but how would such a process be organized?
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
Microsoft Excel 2003 Illustrated Complete Excel Files and Incorporating Web Information Sharing.
15-Jun-15 JDBC. JDBC is a Sun trademark It is often taken to stand for Java Database Connectivity Java is very standardized, but there are many versions.
September 15, 2003Houssam Haitof1 XSL Transformation Houssam Haitof.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
17 Apr 2002 XML Stylesheets Andy Clark. What Is It? Extensible Stylesheet Language (XSL) Language for document transformation – Transformation (XSLT)
Technical Track Session XML Techie Tools Tim Bornholt.
Gayle J Yaverbaum, PhD Professor of Information Systems Penn State Harrisburg.
Introduction to XSLT & its use in Grainger Library full-text & metadata projects Thomas G. Habing Grainger Engineering Library Presentation to ASIS&T,
CVSQL 2 The Design. System Overview System Components CVSQL Server –Three network interfaces –Modular data source provider framework –Decoupled SQL parsing.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Sheet 1XML Technology in E-Commerce 2001Lecture 6 XML Technology in E-Commerce Lecture 6 XPointer, XSLT.
JSP Standard Tag Library
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
1 Understanding Cocoon2 Pankaj Kumar May 24, 2001 Web Services Organization HPMD, SSO, HP.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
16-1 The World Wide Web The Web An infrastructure of distributed information combined with software that uses networks as a vehicle to exchange that information.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
XML for E-commerce III Helena Ahonen-Myka. In this part... n Transforming XML n Traversing XML n Web publishing frameworks.
XP New Perspectives on XML Tutorial 6 1 TUTORIAL 6 XSLT Tutorial – Carey ISBN
WORKING WITH XSLT AND XPATH
Session II Chapter 2 – Chapter 2 – XSLhttp://
Dynamic Data Exchanges with the Java Flow Processor Presenter: Scott Bowers Date: April 25, 2007.
Examples of Using Servlets and JSP Representation and Management of Data on the Internet.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
Sheet 1XML Technology in E-Commerce 2001Lecture 7 XML Technology in E-Commerce Lecture 7 XSL Formatting Objects, Java Data Binding.
Copyright © Orbeon, Inc. All rights reserved. Erik Bruchez Applications of XML Pipelines XML Prague, June 16 th, 2007.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
3/29/2001 O'Reilly Java Java API for XML Processing 1.1 What’s New Edwin Goei Engineer, Sun Microsystems.
Intro. to XML & XML DB Bun Yue Professor, CS/CIS UHCL.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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 "
MDCFUG Is Java in Your Future? Tyler Williams Principal dataTerrace
Servlets Database Access. Agenda:  Setup Java Environment  Install Database  Install Database Drivers  Create Table and add records  Accessing a.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
WEB BASED DATA TRANSFORMATION USING XML, JAVA Group members: Darius Balarashti & Matt Smith.
1 Committed to Shaping the Next Generation of IT Experts. Chapter 8 Exchanging Data Between Access and Other Applications Exploring Microsoft Office Access.
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.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML and Database.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Module: Software Engineering of Web Applications Chapter 2: Technologies 1.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Martin Kruliš by Martin Kruliš (v1.1)1.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
CHAPTER 7 LESSON C Creating Database Reports. Lesson C Objectives  Display image data in a report  Manually create queries and data links  Create summary.
1 Download current version of Tomcat from: g/tomcat/ g/tomcat/ Install it in: C:\Program Files\Apache.
Apache Cocoon – XML Publishing Framework 데이터베이스 연구실 박사 1 학기 이 세영.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
1 Introduction SAX. Objectives 2  Simple API for XML  Parsing an XML Document  Parsing Contents  Parsing Attributes  Processing Instructions  Skipped.
Lecture Transforming Data: Using Apache Xalan to apply XSLT transformations Marc Dumontier Blueprint Initiative Samuel Lunenfeld Research Institute.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
I Copyright © 2004, Oracle. All rights reserved. Introduction.
XML in Web Technologies
Microsoft Office Illustrated
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
XML Problems and Solutions
Unit 6 - XML Transformations
Presentation transcript:

1 XML and Web App 1

Objectives 2  Building Database-Driven Applications  Building Data Exchange Applications  Workshops

Generating XML Data from DB  There are four widely practiced method of retrieving data  Application-Specific Query Language: such as OpenText has syntaxes  XMLPath (XPath):  Can be used as query language.  The XPath expression can be converted in to SQL in order to search the database, which has XML documents.  XMLQuery (XQuery):  Is a standard language for XML documents specified by W3C.  Is an SQL based language, and part of an XML document is addressed by XPath.  Structured Query Language (SQL):  RDMS can be accessed using a common language, SQL.  Can be used to access XML document, which is decomposed into data to be stored in a tables as column or can be generated from the database

Methods of Transforming Data into HTML  With the help of XSLT stylesheets, you can transform XML into some other format, such as, HTML.  There are three ways  Client-Side Transformation: the browser, which is fed with both XML document and stylesheet, transforms the document as specified in the stylesheet. The document is then presented to the user.  Server-Side Transformation: the XSLT stylesheet is used by the server side to convert the document into the other format. The transformed document is then transferred to the client, that is, Web browser.  External Transformation: Sometime the original XML document is external transformed and then fed to the server. In this case, both the server and client deal with the already transformed document.

Example

Example (cont)

Portable Document Format (pdf)  Was developed by Adobe for US government to store legacy files.  Contains metadata, such as XML tables or content and links, making images more useful to end users.  Can be produced by Extensible Stylesheet Language Formatting Object (XSL-FO)  Advantages  Smaller files  Compatibility with various operating systems  Free reader software  Secure and virus resistant  Secure and change resistant  Can contain hyperlinks

Transforming Data into pdf  Converting XML to XSL-FO Using XSLT:  Is a transformation of XML into XSL-FO that uses XML syntax  The process of transformation takes place through the use of XSLT.  SAX or DOM based processing of the XML document can also be used for obtaining XSL-FO document.  XSL-FO document describe the page details, such as size of the page, details such as pagination, font, and color. These details are expressed using XSL formatting objects, for example, fo:page-sequency, fo: block, fo:footnote, fo:float, and fo:region-body, and the formatting properties, such as background- attachment, background-color, font-family, and text-depth.  Processing XSL-FO Using Formatting Engine  Once the XSL-FO is document is ready, FO or XSL formatter is pressed into action to convert XSL-FO elements into a PDF, XSL-FO is not coded manually.  XSLT stylesheet is utilized to convert XML into XSL-FO. The rendering engine is then used to convert XSL-FO into the required print documents. The images and fonts can be specified in the XSL-FO document.

Mechanism XML FO fo:block fo:inline XSLT Area Structure region-before region-after region-body content

Formating Object - FO

Formatting Object Processor – FOP  The tools of softwate is implemented using FO  The latest implementation of XSL Formatting Objects is Formatting Object Processor (FOP).  Download at  FOP can be run from the command line using the FOP batch file. fop –fo inputfile.fo –pdf pdffile.pdf  inputfile.fo: is the file that contains the formatting objects  pdffile.pdf: the output file is the resulting PDF file

Steps for using FOP manually  Using fop.jar file (set CLASSPATH)  set PATH to execute (fop.bat) file  Create document with xml or fo extension  Typing and executing the command  fop –fo -pdf fileName.pdf

Example Header in a box

Example (cont) Subject: Welcome to Grammatically Correct Thanks for requesting the first lesson in the Grammatically Correct Workshop. This is a practical, hands-on course designed to improve your work through a suggested To Do list at the end of each lesson. ……

Example (cont)

Transforming Data into pdf on Server

Example public class FOPServlet extends HttpServlet { protected void processRequest (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{ File file = new File("GrammarDoc.fo.xml"); FileInputStream input = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream(); response.setContentType ("application/pdf"); Driver driver = new Driver(new InputSource(input), out); Logger log = new ConsoleLogger(ConsoleLogger.LEVEL_WARN); driver.setRenderer (Driver.RENDER_PDF); driver.run (); byte[] content = out.toByteArray (); response.setContentLength (content.length); response.getOutputStream ().write (content); response.getOutputStream ().flush (); }catch(Exception e){ e.printStackTrace (); }

Example (cont)  The support libraries  import org.apache.avalon.framework.logger.ConsoleLogger;  import org.apache.avalon.framework.logger.Logger;  import org.apache.fop.apps.Driver;  import org.apache.fop.apps.XSLTInputHandler;  import org.xml.sax.InputSource;  The supporting packages  avalon-framework-cvs jar  batik.jar  fop.jar  xalan jar  xercesImpl jar  xml-apis.jar

Example (cont)

Building data exchange application  Importing XML Data into Databases  JSP can add data from XML document into SQL Server database.  JSP instantiates SAXProcessor Java class, a custom class, and calls its save() method to parse the document.  The SAXProcessor passes the SAX events to another custom class called, which handles the events.  The event handler creates an object for each element encountered in the document.  The process initializes the fields of the object with the data obtained from the sub elements of the element.  The object eventually uses a connection class to store the data into SQL Server.  Exporting XML Data from Databases  The JSP page picks up all active table from SQL Server database.  The retrieved data is first put into XML format.  Applying s stylesheet to this XML data converts it into HTML, which is then presented to the user.

Example – Import  processing.jsp Processing Adding XML Data to SQL Server DB.....

Example – Import (cont)  SAXProcessor public class SAXProcessor { private String msg = ""; public String save(){ DocumentProcessor doc = new DocumentProcessor(); SAXParserFactory spf = SAXParserFactory.newInstance (); try { SAXParser parser = spf.newSAXParser (); parser.parse (new File("CustomerAccount.xml"), doc); msg = doc.getMsg (); msg += "Successfully added XML data"; }catch(Exception e){ msg = e.getMessage (); } return msg; }

Example – Import (cont)  DocumentProcessor public class DocumentProcessor extends DefaultHandler { private boolean usernameFound = false, passwordFound = false; private String msg = ""; private OrderI order = null; public String getMsg(){return msg;} public void startElement (String uri, String localName, String qName, Attributes attributes) throws SAXException { if(qName.equals ("customer")){ order = new OrderI();} if(qName.equals ("username")){ usernameFound = true;} if(qName.equals ("password")){passwordFound = true;} } public void characters (char[] ch, int start, int length) throws SAXException { String str = new String(ch, start, length).trim(); if(usernameFound){ order.setUsername (str); usernameFound = false;} if(passwordFound){ order.setPassword (str); passwordFound = false;} } public void endElement (String uri, String localName, String qName) throws SAXException { if(qName.equals ("customer")){ msg = order.saveAccount (); order = null; }

Example – Import (cont)  OrderI public class OrderI implements Serializable { private String msg = "", username, password; private Connection con = null; private int count = 1; public OrderI (String username, String password) { this.username = username;this.password = password;} public OrderI(){ this.username = "";this.password = "";} public String saveAccount(){ try { connecting DB Statement stm = con.createStatement (); String sql = "Insert into users values('" + this.username + "', '" + this.password + "')"; stm.execute (sql); con.commit (); con.close (); } catch(ClassNotFoundException e){ msg += e.getMessage (); } catch(SQLException e){msg += e.getMessage (); } catch(Exception e){msg += e.getMessage ();} return msg; } building get/set method for msg, username, password properties }

Example – Import (cont)  CustomerAccount.xml khanhAPT khanhFU

Example – Import (cont) Notes: the inputted xml file must be located at address InstalledDirectoryforNetBean Or must applying the getRealPath() method of ServletContext

Retrieving data from DB in XML  JSP is capable of retrieving data from a database with the help of JDBC. It is also capable of generating XML documents from the retrieved data.  XSLT can transform the retrieved data into various formats, such as PDF and HTML  Creating an XML file from SQL Server 2005 database using the following steps:  Create a DTD Document (optional)  Connect to SQL Server and Retrieve Data  Generate XML File

Example – Export  index.jsp <% Iterator orderList = orders.getOrders (); Order trade = null; %> <% while (orderList.hasNext ()){ trade = (Order)orderList.next (); %>

Example – Export (cont)  OrderBean public class OrderBean implements Serializable{ private Vector orders = new Vector(); private Connection con = null; private ResultSet rs = null; public OrderBean () { try { connecting DB Statement stm = con.createStatement (); String sql = "Select * From users"; rs = stm.executeQuery (sql); while (rs.next ()){ orders.addElement (new Order(rs.getString (1), rs.getString (2))); } con.close (); } catch(ClassNotFoundException e){e.printStackTrace (); } catch(SQLException e){e.printStackTrace (); } catch(Exception e){e.printStackTrace (); } public Iterator getOrders(){return orders.iterator ();} }

Example – Export (cont)  Order public class Order implements Serializable { private String username; private String password; public Order (String username, String password) { this.setUsername(username); this.setPassword(password); } building get/set methods to username/password } Notes: the inputted xslt file must be located at address of the contextRoot of Web application

Example – Export (cont)  OrderProcessing.xslt Customers Orders UserName Password

WORKSHOP ACTIVITIES Building the Java Web application using XML combining with DB to Export data from DB to present html file applying xslt file Import data to DB from XML to DB file using SAX