Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.

Slides:



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

Bruce Scharlau, University of Aberdeen, 2010 Java ME Networking Mobile Computing Some slides from MobEduNet This covers HTTP in detail, and mentions other.
XML and Databases By Jared Foster. What is XML? Extensible Markup Language (XML) Similar to HTML XML is about 5 years old Allows information and services.
USING ANDROID WITH THE INTERNET. Slide 2 Network Prerequisites The following must be included so as to allow the device to connect to the network The.
Networking.  Many applications provide & use data & services via the Internet  Android includes multiple networking support classes, e.g.,  java.net.
SAX A parser for XML Documents. XML Parsers What is an XML parser? –Software that reads and parses XML –Passes data to the invoking application –The application.
1 The Simple API for XML (SAX) Part I ©Copyright These slides are based on material from the upcoming book, “XML and Bioinformatics” (Springer-
Xerces The Apache XML Project Yvonne Yao. Introduction Set of libraries that provides functionalities to parse XML documents Set of libraries that provides.
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.
26-Jun-15 SAX. SAX and DOM SAX and DOM are standards for XML parsers--program APIs to read and interpret XML files DOM is a W3C standard SAX is an ad-hoc.
28-Jun-15 StAX Streaming API for XML. XML parser comparisons DOM is Memory intensive Read-write Typically used for documents smaller than 10 MB SAX is.
17 Apr 2002 XML Programming: SAX Andy Clark. SAX Design Premise Generic method of creating XML parser, parsing documents, and receiving document information.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
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.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
SDPL 2003Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
Chapter 17 - Deploying Java Applications on the Web1 Chapter 17 Deploying Java Applications on the Web.
SAX Parsing Presented by Clifford Lemoine CSC 436 Compiler Design.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
SDPL 2002Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
SDPL 20113: XML APIs and SAX1 3. XML Processor APIs n How can (Java) applications manipulate structured (XML) documents? –An overview of XML processor.
Session IV Chapter 9 – XML Schemas
XML Parsers Overview  Types of parsers  Using XML parsers  SAX  DOM  DOM versus SAX  Products  Conclusion.
SAX. What is SAX SAX 1.0 was released on May 11, SAX is a common, event-based API for parsing XML documents Primarily a Java API but there implementations.
Beginning XML 4th Edition. Chapter 12: Simple API for XML (SAX)
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
Java + XML. Java 2 Enterprise Edition Server Side java Servlets JSP JavaBeans Web Services Database jdbc.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
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.
Consuming eXtensible Markup Language (XML) feeds.
SDPL Streaming API for XML1 3.4 Streaming API for XML (StAX) n Could we process XML documents more conveniently than with SAX, and yet more efficiently?
CS 331 – Programming LanguagesDate: Internet Programming Group Presenter: Aren Ray Topics: Internet Programming XML.
WEB APPLICATION DEVELOPMENT For More visit:
Namespace information are represented as namespace node which maps in scope on an element Attach to every element node where namespace is declared root.
Consuming eXtensible Markup Language (XML) feeds.
Web Technologies COMP6115 Session 4: Adding a Database to a Web Site Dr. Paul Walcott Department of Computer Science, Mathematics and Physics University.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 15 IO Using http Rob Pooley
Jennifer Widom XML Data Introduction, Well-formed XML.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
1 Introduction to Web Applications & APIs. 2 Agenda  Architecture of Web Applications Three layer architecture  Web Server (Tomcat) Installation Data.
© Marty Hall, Larry Brown Web core programming 1 Simple API for XML SAX.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
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.
 defined as Extensible Markup Language (XML) is a set of rules for encoding documents  Defines structure and data.
DTD ]>. Internal DTD Declaration ]> Faculty Director Reminder Please be regular in your classes.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
MIDP Programming Networking. Chapter Objectives The CLDC Streams Model Generic Connection Framework (GCF) Supported Protocols Creating a Connection Review.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
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.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
SDPL 20063: XML Processor Interfaces1 3. XML Processor APIs n How can (Java) applications manipulate structured (XML) documents? –An overview of XML processor.
Simple API for XML (SAX) Aug’10 – Dec ’10. Introduction to SAX Simple API for XML or SAX was developed as a standardized way to parse an XML document.
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.
SDPL 2001Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How applications can manipulate structured documents? –An overview of document parser.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
General Architecture of Retrieval Systems 1Adrienn Skrop.
1 Introduction SAX. Objectives 2  Simple API for XML  Parsing an XML Document  Parsing Contents  Parsing Attributes  Processing Instructions  Skipped.
Java API for XML Processing
Simple API for XML SAX. Agenda l Introduction to SAX l Installation and setup l Steps for SAX parsing l Defining a content handler l Examples Printing.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Hypertext Transport Protocol
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
XML Data Introduction, Well-formed XML.
Java API for XML Processing
A parser for XML Documents
Presentation transcript:

Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection

Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection void close()

Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection void close() DIS openDataInputStream() DIS openInputStream() DOS openDataOutputStream() DOS openOutputStream()

Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection void close() DIS openDataInputStream() DIS openInputStream() DOS openDataOutputStream() DOS openOutputStream() String getURL() String getHost() String getPort() long getExpiration() long getLastModified() int getResponseCode()

HttpConnection API  API for processing the URL: http – protocol – server search?hl=en&q=java – file hl=en&q=java – query string

HttpConnection API  API for processing the URL: String url = “ HttpConnection conn = (HttpConnection) Connector.open(url); hc.getURL() -- “ hc.getProtocol() -– “http” hc.getHost() –- “ hc.getPort() hc.getFile() –- “search?hl=en&q=java” hc.getQuery() – “hl=en&q=java”

HttpConnection API  Response Codes ( ) Successful Request 2xx 200 OK (HTTP_OK)-- the request has succeeded Client Error 4xx 403 Forbidden (HTTP_FORBIDDEN) -- server is refusing to fulfill the request 404 Not Found (HTTP_NOT_FOUND)-- server has not found a matching URI Server Error 5xx 500 Internal Server Error (HTTP_INTERNAL_ERROR) -- unexpected error on server 503 Service Unavailable (HTTP_UNAVAILABLE) -- server currently unable to handle request due to temporary overloading or maintenance

Telnet Demo

HttpConnection API  Reading and image through Http connection String url = “ 1. create a connection to the url 2. obtain a data input stream from the connection 3. check the length of the content 3.1 if length > 0: read whole image at once else: read image in chunks until nothing read 4. close the connection

HTTP MIDlet

XML EXtensible Markup Language  Markup language similar to HTML  Not a replacement for HTML  Designed to represent structured data  No predefined tags – you create your own  Simplifies data sharing and data transport

XML Example Everyday Italian Giada De Laurentiis

XML Example  Representation of Book ( ) Everyday Italian Giada De Laurentiis  You decide on the tags,,,,  Tags must be nested properly  Tags are case sensitive

XML Example  Tags, attributes, values Everyday Italian Giada De Laurentiis book – the tag category – attribute “COOKING” – value for attribute category (can have multiple attributes per tag)

XML Example Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray (

XML Parsing  SAX Parser (Simple Api for XML) ( )  SAX Parser is a “push parser” runs through entire document and triggers events on tokens  Selected methods void parse(InputSource is, DefaultHandler dh) parses the input stream and notifies the handler when tokens are discovered to handle tokens must create our own Handler class that extends DefaultHandler

XML Parsing  DefaultHandler – process tokens discovered by parser  Selected Methods // implement to handle beginning and end of document void startDocument() void endDocument() // override to handle discovery and end tags void startElement(String uri, String localName, String qName, Attributes attributes) void endElement(String uri, String localName, String qName)

XML Parsing  Attributes class – retrieve information about the tag’s attributes  Can extract information based on attribute index or name  Selected methods void getLength() – number of attributes String getQName(int index) – get the attribute’s name by index String getQValue(int index) – get attribute’s value by index String getQValue(String qName) – get attribute’s value by its name

XML Parsing  Using the SAX Parser HttpConnection hc = (HttpConnection) Connector.open(url); DataInputStream is = conn.openDataInputStream(); DefaultHandler dh = new MyHandler(); SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser parser = spf.newSAXParser(); parser.parse(is, dh);

Parsing MIDlet

XML Parsing with KXML  KXML – lightweight parser (can use if phone does not support JSR 172)  Download and save in the lib/ folder

XML Parsing with KXML  KXML – lightweight parser (can use if phone does not support JSR 172)  Download and save in the lib/ folder  Selected methods void getEventType() – any of START_DOCUMENT, START_TAG, END_TAG, END_DOCUMENT, TEXT, COMMENT String getName() – get the tag’s name String getText() – get the text value of a tag String getAttributeCount() – number of attributes for current tag String getAttributeName(int i) – get i-th attribute’s name String getAttributeValue(int i) – get i-th attribute’s value

XML Parsing with KXML  KXML – lightweight parser (can use if phone does not support JSR 172)  Download and save in the lib/ folder  Selected methods void getEventType() – any of START_DOCUMENT, START_TAG, END_TAG, END_DOCUMENT, TEXT, COMMENT String getName() – get the tag’s name String getText() – get the text value of a tag String getAttributeCount() – number of attributes for current tag String getAttributeName(int i) – get i-th attribute’s name String getAttributeValue(int i) – get i-th attribute’s value

XML Parsing with KXML InputStream is = hc.openInputStream(); Reader reader = new InputStreamReader(is); KXmlParser parser = new KXmlParser(); parser.setInput(reader); parser.next() while(parser.getEventType() != KXmlParser.END_DOCUMENT) { if (parser.getEventType() == KXmlParser.START_TAG) { } else if (parser.getEventType() == KXmlParser.END_TAG) { } else if (parser.getEventType() == KXmlParser.TEXT) { } parser.next }