XML. Technical Talk. by Svetlana Slavova. CMPT 842, Feb

Similar documents
Web architectures Laurea Specialistica in Informatica Università di Trento. DOM architecture

XML APIs. Web Data Management and Distribution. Serge Abiteboul Philippe Rigaux Marie-Christine Rousset Pierre Senellart

Document Object Model (DOM) Java API for XML Parsing (JAXP) DOM Advantages & Disadvantage &6&7XWRULDO (GZDUG;LD

XPath Basics. Mikael Fernandus Simalango

languages for describing grammar and vocabularies of other languages element: data surrounded by markup that describes it

SAX & DOM. Announcements (Thu. Oct. 31) SAX & DOM. CompSci 316 Introduction to Database Systems

XML Extensible Markup Language

Java and XML. XML documents consist of Elements. Each element will contains other elements and will have Attributes. For example:

Markup Languages SGML, HTML, XML, XHTML. CS 431 February 13, 2006 Carl Lagoze Cornell University

CSC System Development with Java Working with XML

Module 2 (III): XHTML

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

.. Cal Poly CPE/CSC 366: Database Modeling, Design and Implementation Alexander Dekhtyar..

9.3.5 Accessing the Vote Service

extensible Markup Language (XML) Announcements Sara Sprenkle August 1, 2006 August 1, 2006 Assignment 6 due Thursday Project 2 due next Wednesday

CSC Web Technologies, Spring Web Data Exchange Formats

XML An API Persepctive. Context. Overview

Lecture 2: Tools & Concepts

Extensible Markup Language (XML) Hamid Zarrabi-Zadeh Web Programming Fall 2013

What is XHTML? XHTML is the language used to create and organize a web page:

Intro to XML. Borrowed, with author s permission, from:


Using netbeans create a new Web Application and select the framework as JSF 2.2

A POLICY-BASED DIALOGUE SYSTEM FOR PHYSICAL ACCESS CONTROL

XML extensible Markup Language

Software Engineering Methods, XML extensible Markup Language. Tutorial Outline. An Example File: Note.xml XML 1

XML. Jonathan Geisler. April 18, 2008

CSI 3140 WWW Structures, Techniques and Standards. Representing Web Data: XML

Introduction Syntax and Usage XML Databases Java Tutorial XML. November 5, 2008 XML

Why HTML5? Why not XHTML2? Learning from history how to drive the future of the Web

XML Structures. Web Programming. Uta Priss ZELL, Ostfalia University. XML Introduction Syntax: well-formed Semantics: validity Issues

Session 23 XML. XML Reading and Reference. Reading. Reference: Session 23 XML. Robert Kelly, 2018

The concept of DTD. DTD(Document Type Definition) Why we need DTD

Introduction to Programming Using Java (98-388)

XML. extensible Markup Language. Overview. Overview. Overview XML Components Document Type Definition (DTD) Attributes and Tags An XML schema

XML for Java Developers G Session 3 - Main Theme XML Information Modeling (Part I) Dr. Jean-Claude Franchitti

XML: Introduction. !important Declaration... 9:11 #FIXED... 7:5 #IMPLIED... 7:5 #REQUIRED... Directive... 9:11

HTML Overview. With an emphasis on XHTML

Handouts. 2 Handouts for today! Manu Kumar. Recap. Today. Today: Files and Streams (Handout #26) Streams!?? #27: XML #28: SAX XML Parsing

What is XML? XML is designed to transport and store data.

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 27-1

SDN Community Contribution

Introduction to XML. M2 MIA, Grenoble Université. François Faure

extensible Markup Language (XML) Basic Concepts

HTML. Mohammed Alhessi M.Sc. Geomatics Engineering. Internet GIS Technologies كلية اآلداب - قسم الجغرافيا نظم المعلومات الجغرافية

XML Programming in Java

Oral Question Bank for CL-3 Assignment

Parsing XML documents. DOM, SAX, StAX

CHAPTER 2 MARKUP LANGUAGES: XHTML 1.0

Author: Irena Holubová Lecturer: Martin Svoboda

XML for Java Developers G Session 3 - Main Theme XML Information Modeling (Part I) Dr. Jean-Claude Franchitti

Introduction to XML Zdeněk Žabokrtský, Rudolf Rosa

Knowledge Engineering pt. School of Industrial and Information Engineering. Test 2 24 th July Part II. Family name.

XML. Objectives. Duration. Audience. Pre-Requisites

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

Chapter 10: Understanding the Standards

XHTML. XHTML stands for EXtensible HyperText Markup Language. XHTML is the next generation of HTML. XHTML is almost identical to HTML 4.

Session 17. JavaScript Part 2. W3C DOM Reading and Reference. Background and introduction.

Data Presentation and Markup Languages

Streaming API for XML. Asst. Prof. Dr. Kanda Runapongsa Saikaew Dept. of Computer Engineering Khon Kaen University

EXPERIMENT OBJECTIVE:

Overview. Introduction. Introduction XML XML. Lecture 16 Introduction to XML. Boriana Koleva Room: C54

XML: Managing with the Java Platform

Wicket and Aida/Web Brief Comparison

Scripting for Multimedia LECTURE 1: INTRODUCING HTML5

XML Querying and Communication Classes for the VizIR Framework

COE318 Lecture Notes Week 10 (Nov 7, 2011)

About this exam review

Controls Structure for Repetition

Computer Science E-75 Building Dynamic Websites

Simple API for XML (SAX)

XML. XML Syntax. An example of XML:

I/O and Parsing Tutorial

COMP519 Practical 5 JavaScript (1)

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 7 XML

Lab Assignment 3 on XML

Text User Interfaces. Keyboard IO plus

Client-side Web Engineering 2 From XML to Client-side Mashups. SWE 642, Spring 2008 Nick Duan. February 6, What is XML?

utidylib Documentation Release 0.4

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Delivery Options: Attend face-to-face in the classroom or via remote-live attendance.

/ Introduction to XML

The Extensible Markup Language (XML) and Java technology are natural partners in helping developers exchange data and programs across the Internet.

XML and DTD. Mario Alviano A.Y. 2017/2018. University of Calabria, Italy 1 / 28

TagSoup: A SAX parser in Java for nasty, ugly HTML. John Cowan

Processing XML Documents with DOM Using BSF4ooRexx

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

The Xlint Project * 1 Motivation. 2 XML Parsing Techniques

Understanding the Vex Rendering Engine

Technical University of Braunschweig. Institute of Operating Systems and Networks

Introduction to XML. An Example XML Document. The following is a very simple XML document.

Processing XML Documents with SAX Using BSF4ooRexx

CS193j, Stanford Handout #29 XML. Suppose you have a bunch of dots (x,y pairs) you need to represent in a program for processing.

Chapter 13 XML: Extensible Markup Language

Introduction to XML. XML: basic elements

Introduction to HTML5

Delivery Options: Attend face-to-face in the classroom or remote-live attendance.

7.1 Introduction. extensible Markup Language Developed from SGML A meta-markup language Deficiencies of HTML and SGML

Options for User Input

Transcription:

XML Technical Talk by Svetlana Slavova 1

Outline Introduction to XML XML vs. Serialization Curious facts, advantages & weaknesses XML syntax Parsing XML Example References 2

Introduction to XML (I) XML (EXtensible Markup Language) is a standard Mechanism for encoding data that is independent of any programming language XML is used for data exchange 3

Introduction to XML (II) XML has a nested structure that allows to describe hierarchical data sets XML describes the meaning of data, not how to display them (HTML describes how to display the data) The recipient can easily parse the XML document & get the necessary data 4

XML vs. Serialization Object serialization can be used to exchange binary data that describe the objects In particular, the recipient must be a Java/C# program that uses the same versions of classes as the sending program 5

XML curious facts XML was designed by an 11-member group that never met face-to-face The design was accomplished using weekly email teleconferences The major design decisions were reached only in 20 weeks in 1996 XML 1.0 became a W3C Recommendation in 1998 6

XML advantages Human- & machine-readable format Can represent the most general computer science data structures: records, lists, and trees The strict syntax allows the parsing algorithms to remain simple, efficient, and consistent 7

XML weaknesses The parsers have to check if the XML documents are properly formatted The basic parsing requirements do not support a wide variety of data types => additional work is necessary in order to process the desired data from a XML document 8

XML syntax (I) XML structure XML declaration XML schema XML elements 9

XML syntax (II) XML declaration <?xml version="1.0" encoding="utf-8"?> XML schema <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1- transitional.dtd"> 10

XML syntax (III) XML elements <element_tag>content</element_tag> <element_tag attributes>content<element_tag> <element_tag attributes /> <temperature>-30</temperature> <temperature name="c">-30</temperature> <temperature value="-30" /> 11

XML syntax (IV) <coin value="1" name="loonie" /> <coin> <name>loonie</name> <value>1</value> </coin> 12

XML syntax (IV) Character encoding Unicode < 俄语 >Данни</ 俄语 > 13

XML syntax (V) Every XML document must have exactly one top-level root element <?xml version="1.0" encoding="utf-8"?> <class842>cmpt 842</class842> Wrong! <class880>cmpt 880</class880> <?xml version="1.0" encoding="utf-8"?> <classes> <class842>cmpt 842</class842> <class880>cmpt 880</class880> </classes> Correct! 14

Parsing XML SAX (Simple Access to XML) Parser Event-driven parser whenever the parser encounters a particular construct, then it calls a method that you must provide More efficient for large documents do not build a tree More complex DOM (Document Object Model) Parser Builds up a tree that represents the XML document Easy to use 15

Example (I) <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/dtd/xhtml1- transitional.dtd"> <coin> <name>loonie</name> <value>1</value> </coin> 16

Example (II) /* * Parser.java * @author Svetlana Slavova, sds797@mail.usask.ca * @version 1.0, February, 2006 */ package xmlparsing; import java.util.vector; import java.io.*; import javax.xml.parsers.*; import org.w3c.dom.*; 17

public class Parser //To get a DOM document from the XML document private DocumentBuilder builder; /** Creates a new instance of Parser. */ public Parser() try //The program obtains a parser that creates the DOM tree DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); builder = factory.newdocumentbuilder(); } catch (Exception ex) System.out.println("Error in the constructor: " + ex); } } 18

/** Parses the XML document. */ public Vector parse(string filename) try File f = new File(filename); //Create the DOM tree Document doc = builder.parse(f); //Get the root element of the tree Element root = doc.getdocumentelement(); Vector v = getcoin(root); return v; } catch (Exception ex) System.out.println("Error in method parse: " + ex); return null; } } 19

/** Gets information about the coin. */ private Vector getcoin(element e) Vector items = new Vector(); int value = -1; String name = ""; try //Get the children NodeList children = e.getchildnodes(); for (int i = 0; i < children.getlength(); i++) //Get a node Node childnode = children.item(i); 20

if (childnode instanceof Element) Element childelement = (Element) childnode; String tagname = childelement.gettagname(); Text textnode = (Text) childelement.getfirstchild(); String data = textnode.getdata(); if (tagname.equals("value")) value = Integer.parseInt(data); else if (tagname.equals("name")) name = data; else System.out.println("Unknown tag element"); } } } //End for loop 21

//Add the name & the value to the Vector items.addelement(name); items.addelement(value); return items; } //End try block catch (Exception ex) System.out.println("Error in method getcoin: " + ex); return null; } } //End getcoin method 22

public static void main(string[] args) Parser p = new Parser(); String filename = "../XML.xml"; Vector items = p.parse(filename); } System.out.println("Coin information:"); System.out.println("name = " + items.elementat(0)); System.out.println("value = " + items.elementat(1)); System.out.println("----------------------------------"); } //End of the class 23

Example (III) Result Coin information: name = loonie value = 1 ---------------------------------- 24

References Big Java, Cay Horstmann http://en.wikipedia.org/wiki/xml 25

26