java & xml for public access television advanced internet issues david moisan july 9th, 1999

80
Java & XML for Java & XML for Public Access Television Public Access Television Advanced Internet Issues Advanced Internet Issues David Moisan David Moisan July 9th, 1999 July 9th, 1999

Upload: alison-sanders

Post on 26-Dec-2015

224 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Java & XML for Java & XML for Public Access TelevisionPublic Access Television

Advanced Internet IssuesAdvanced Internet Issues

David MoisanDavid Moisan

July 9th, 1999July 9th, 1999

Page 2: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

JavaJava

Page 3: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Introduction—What is JavaIntroduction—What is Java

Java is an object-oriented programming Java is an object-oriented programming language and environment designed language and environment designed specifically for the Internet specifically for the Internet

Java is Java is cross-platformcross-platform, running on many , running on many different machines by using a different machines by using a Java Virtual Java Virtual MachineMachine that translates Java code to that of that translates Java code to that of the machine it runs on.the machine it runs on.

Java has networking capabilities.Java has networking capabilities.

Page 4: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

What is Object-oriented What is Object-oriented

Programming?Programming? Traditional languages like C, BASIC and Traditional languages like C, BASIC and

Pascal are proceduralPascal are procedural– They describe how to do something with data, but They describe how to do something with data, but

the data & program are separate things; functions the data & program are separate things; functions are called on data but data is separate from codeare called on data but data is separate from code

Page 5: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Java is Object-orientedJava is Object-oriented

But Java is But Java is object-orientedobject-oriented– Every piece of data in a program is an Every piece of data in a program is an object object that that

has has methods methods to manipulate itselfto manipulate itself– Objects are arranged by Objects are arranged by classesclasses of related objects of related objects

that represent data of some typethat represent data of some type

Page 6: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Benefits of Object-Oriented Benefits of Object-Oriented LanguagesLanguages Keep data and algorithms together Keep data and algorithms together Hide details from other modulesHide details from other modules Confine bugs to modules—no global Confine bugs to modules—no global

variables!variables!

Page 7: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Java & Javascript: What’s the Java & Javascript: What’s the difference?difference? Javascript has many similarities to Java but Javascript has many similarities to Java but

was developed separately from Javawas developed separately from Java Javascript is meant for lightweight Javascript is meant for lightweight

programming inside web pagesprogramming inside web pages Javascript syntax is simpler and less Javascript syntax is simpler and less

restrictive than Javarestrictive than Java

Page 8: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Java SyntaxJava Syntax

Java’s syntax is very similar to C.Java’s syntax is very similar to C. Standard control structures includeStandard control structures include

– if (i>array.length) {…some code…}if (i>array.length) {…some code…}

……else {…more code…}else {…more code…}– while (vector.moreelements()) {…code…}while (vector.moreelements()) {…code…}– do {} while (condition)do {} while (condition)– for (int i=1;i<10,i++) {…some codefor (int i=1;i<10,i++) {…some code…}…}

Java has primitive variables like C: ints, floats, Java has primitive variables like C: ints, floats, arrays, etc. arrays, etc.

Page 9: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Differences between Java and Differences between Java and C/C++C/C++ Java is purely object oriented, unlike C++Java is purely object oriented, unlike C++ Java does not allow direct manipulation of Java does not allow direct manipulation of

pointers, reducing a major source of bugspointers, reducing a major source of bugs Java reclaims unused memory through Java reclaims unused memory through

garbage collectiongarbage collection, so memory allocation , so memory allocation bugs as found in C and C++ are all but bugs as found in C and C++ are all but unheard of.unheard of.

Page 10: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

““HelloWorld” applicationHelloWorld” application

public class HelloWorld {

// Classic "Hello World!" program

// D. Moisan 6/20/1999

public static void main (String args[]) {

System.out.println("Hello World!");

System.exit(0);

}}

Page 11: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Running “HelloWorld”Running “HelloWorld”

Page 12: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A simple objectA simple object

class Car {

String Make;String Model;String Engine;

int Wheels;int Seats;

// This is a simple class Car with field// variables }

Page 13: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

FieldsFields

class Car {

String Make;String Model;String Engine;

int Wheels;int Seats;

// Fields are variables or other objects// in a class that hold data}

Page 14: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

MethodsMethods

// Methods work just like functions—they// are code that does thingsclass Car {… public drive(String direction, speed) {// drive this car somewhere

this.moveCar(direction, speed);System.out.println(“Moving :” +_direction+ “at “+ speed);}}

Page 15: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Creating Objects: ConstructorsCreating Objects: Constructors

… Car MyCar = new Car(“Chevy”, “Corvette”);…

Constructors are used to create and Constructors are used to create and initialize objectsinitialize objects

Page 16: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Defining ConstructorsDefining Constructors

class Car {… public Car(String make, String Model) {this.Make = make;this.Model = model;// this keyword refers to the current object

}

Constructors are defined just like methods Constructors are defined just like methods are, but with a special method of the same are, but with a special method of the same name as the classname as the class

Page 17: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Subclasses & InheritanceSubclasses & Inheritance

class SportsCar extends Car {int CubicInchDisplacement = 350;}

class CompactCar extends Car {int CrushLoad = 5;this.Make = “Kia”;

Page 18: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Inheritance DiagramInheritance Diagram

ObjectObject

VehicleVehicle

CarCar

SportsCarSportsCar

TruckTruck

Page 19: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

The Class LibraryThe Class Library

Most of Java’s power and capabilities come from the Most of Java’s power and capabilities come from the class libraryclass library; similar to the standard library in C or C+; similar to the standard library in C or C++, it defines the standard functions in Java+, it defines the standard functions in Java

Some standard class packages:Some standard class packages:– java.langjava.lang: Language & system features, always : Language & system features, always

includedincluded– java.iojava.io: File and stream I/O: File and stream I/O– java.netjava.net: Networking: Networking– java.appletjava.applet: Applets: Applets– java.awtjava.awt: The Abstract Window Toolkit GUI: The Abstract Window Toolkit GUI

Page 20: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Applets—Java in the BrowserApplets—Java in the Browser

An applet is a piece of program code An applet is a piece of program code designed to run from within a web browserdesigned to run from within a web browser

Applets can draw graphics and interact with Applets can draw graphics and interact with the userthe user

Applets are Applets are restrictedrestricted in what they can do on in what they can do on the client machine—they “play in a sandbox”the client machine—they “play in a sandbox”

Applets can be Applets can be digitally signeddigitally signed for greater for greater privileges, such as in an intranet.privileges, such as in an intranet.

Page 21: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

““HelloWorldWeb” AppletHelloWorldWeb” Applet

import java.applet.*; import java.awt.*;

public class HelloWorldApplet extends Applet {

// This method displays the applet. // The Graphics class is how you do all drawing in Java.

public void paint(Graphics g) { g.drawString("Hello World", 25, 50); }}

Page 22: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

““HelloWorldApplet” HTMLHelloWorldApplet” HTML

… <h1>HelloWorldApplet Example</h1>

<applet height="100" width="100" code="HelloWorldApplet.class">

Sorry, a Java-enabled browser is needed to view this applet

</applet>…

Applets are invoked in the web browser by Applets are invoked in the web browser by the the <APPLET><APPLET> tag tag

Page 23: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

““Hello,World” on the BrowserHello,World” on the Browser

Page 24: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Differences between Applets Differences between Applets and Applicationsand Applications Applications start running with a call to Applications start running with a call to main()main(), the body of the program and run , the body of the program and run outside the browseroutside the browser

Applets define four methods used by the Applets define four methods used by the browser to control applet execution, browser to control applet execution, init()init(), , start()start(), , stop()stop() and and destroy()destroy(), and also , and also paint() paint() for graphics.for graphics.

Page 25: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Other Language FeaturesOther Language Features

Some other language features you should know Some other language features you should know about:about:

Java Beans--code modules that can be Java Beans--code modules that can be “plugged in” to applications.“plugged in” to applications.

Abstract Window Toolkit (AWT)--Java’s older Abstract Window Toolkit (AWT)--Java’s older GUI interfaceGUI interface

Swing--Java’s new GUI interface standard to Swing--Java’s new GUI interface standard to replace AWTreplace AWT

Page 26: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

The Various Versions of JavaThe Various Versions of Java

There are three versions of Sun’s Java:There are three versions of Sun’s Java:– Java 1.0.2:Java 1.0.2: Still seen on older browsers Still seen on older browsers– Java 1.1:Java 1.1: The most common version The most common version– Java 1.2:Java 1.2: The newest version of Java, also known The newest version of Java, also known

as Java2.as Java2.

Sun also provides extra API’s to extend Java, Sun also provides extra API’s to extend Java, most notably the Multimedia API which most notably the Multimedia API which supports streaming media, and Swing, Java’s supports streaming media, and Swing, Java’s new GUI.new GUI.

Page 27: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Even More Java ChoicesEven More Java Choices

In addition, other companies have released In addition, other companies have released their own Java VM’s:their own Java VM’s:– IBM Alphaworks (a IBM Alphaworks (a bigbig player) player)– MicrosoftMicrosoft– JVM’s exist for Linux and Mac too.JVM’s exist for Linux and Mac too.

Many other companies offer Java tools and Many other companies offer Java tools and productsproducts

Page 28: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Developing Java: Developing Java: Writing & Compiling CodeWriting & Compiling Code The compiler and other tools that come with The compiler and other tools that come with

the Java Development Kit (JDK) are the Java Development Kit (JDK) are command-line oriented.command-line oriented.

But there are several free graphical But there are several free graphical development packages, most notably IBM’s development packages, most notably IBM’s Visual Age for Java Basic EditionVisual Age for Java Basic Edition

One of my favorite tools for Windows is One of my favorite tools for Windows is Programmer’s File EditorProgrammer’s File Editor (PFE). (PFE).

Page 29: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Developing Java: Developing Java: Where to get toolsWhere to get tools Sun’s website (Sun’s website (http://java.sun.com/http://java.sun.com/) is the canonical ) is the canonical

resource.resource. Gamelan (Gamelan (http://www.gamelan.com/http://www.gamelan.com/)) has been has been thethe

Java directory since the beginningJava directory since the beginning IBM’s Alphaworks site IBM’s Alphaworks site

((http://www.alphaworks.ibm.com/http://www.alphaworks.ibm.com/) is a treasure ) is a treasure trove of Java and XML applications, all free, many trove of Java and XML applications, all free, many with source code!with source code!

Page 30: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Recommendations & More Recommendations & More InformationInformation Which version of Java should you use? Which version of Java should you use?

– Java 1.0.2Java 1.0.2: Obsolete; use only to support older : Obsolete; use only to support older browsersbrowsers

– Java 1.2 (Java2):Java 1.2 (Java2): “Bleeding-edge Java”; not all “Bleeding-edge Java”; not all browsers support it yetbrowsers support it yet

– Java 1.1:Java 1.1: Widespread support; your best choice Widespread support; your best choice Links to all Java resources in this presentation Links to all Java resources in this presentation

can be found at:can be found at:http://www1.shore.net/~dmoisan/comp/http://www1.shore.net/~dmoisan/comp/

javaresources.htmljavaresources.html

Page 31: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XMLXML

Page 32: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

What is XML?What is XML?

XML—Extensible Markup Language—is an open, XML—Extensible Markup Language—is an open, standard, format for transporting data.standard, format for transporting data.

It resembles HTML, with a difference: You define It resembles HTML, with a difference: You define your own tags to describe your datayour own tags to describe your data

XML is not so much a XML is not so much a languagelanguage, but a means of , but a means of defining our own markup languages for specific defining our own markup languages for specific applications.applications.

It’s similar to SGML but has been simplified for the It’s similar to SGML but has been simplified for the Web.Web.

Page 33: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

What can be represented with What can be represented with XML?XML? Textual information, such as scriptsTextual information, such as scripts Simple, flat-file, databasesSimple, flat-file, databases Any information that needs to be transferred Any information that needs to be transferred

across applications and platforms.across applications and platforms.

Page 34: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XML in the Access Center—XML in the Access Center—What can it do for us?What can it do for us? Many access centers have to work with a limited staff Many access centers have to work with a limited staff

& budget & budget Because we are a niche market and relatively ill-Because we are a niche market and relatively ill-

funded, there is little available that we can afford.funded, there is little available that we can afford. Many of our activities need to be tied together and Many of our activities need to be tied together and

tightly integrated.tightly integrated. XML can help!XML can help!

Page 35: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A typical problem: SchedulingA typical problem: Scheduling

At Salem Access TV, we generate weekly At Salem Access TV, we generate weekly schedules that go on our website, to our schedules that go on our website, to our board members, to the newspaper, to our board members, to the newspaper, to our video bulletin board and to our automation video bulletin board and to our automation controller.controller.

Our program coordinator has to reenter the Our program coordinator has to reenter the week’s schedule as often as week’s schedule as often as fivefive times or times or more!more!

Page 36: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A Scheduling ProblemA Scheduling Problem

The Old Way:The Old Way:Entering Schedules One at a TimeEntering Schedules One at a Time

Page 37: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Is XML a solution?Is XML a solution?

One solution to this problem is to define a common One solution to this problem is to define a common format for schedules that can be used across SATV format for schedules that can be used across SATV in a variety of different applicationsin a variety of different applications

The schedule is entered The schedule is entered onceonce as an XML file… as an XML file… ……and is rendered by software and stylesheets to and is rendered by software and stylesheets to

provide as many different “views” as needed.provide as many different “views” as needed.

Page 38: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

An XML SolutionAn XML Solution

An XML Solution:An XML Solution:One Document: Many ApplicationsOne Document: Many Applications

XML

Page 39: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Why use XML—Why don’t we Why use XML—Why don’t we use HTML? use HTML? You can’t determine You can’t determine whatwhat the data is in HTML the data is in HTML

—HTML has structural information but little or —HTML has structural information but little or no semantics.no semantics.

HTML is overburdened and hard to extend in HTML is overburdened and hard to extend in its present formits present form

HTML was never designed to be used by HTML was never designed to be used by automation such as robots and agentsautomation such as robots and agents

Page 40: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

HTML and XML comparedHTML and XML compared

Compare these two snippets of markupCompare these two snippets of markup

Which one is easier to interpret?Which one is easier to interpret?

First, the HTML version:First, the HTML version:

<br><h4><br><h4>Monday, May 24thMonday, May 24th</h4></h4>

3:00 PM: Salem High 3:00 PM: Salem High BasketballBasketball<strong><strong>vs. Lynn vs. Lynn ClassicalClassical</strong></strong>

Page 41: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

HTML and XML comparedHTML and XML compared

The XML version:The XML version:<<DATE>DATE>Monday, May 24th, 1999Monday, May 24th, 1999</DATE></DATE>

<PROGRAMSLOT><PROGRAMSLOT>

<TIME><TIME>3:00 PM3:00 PM</TIME></TIME>

<TITLE><TITLE>Salem High BasketballSalem High Basketball</TITLE></TITLE>

<DESCRIPTION><DESCRIPTION>vs. Lynn Classicalvs. Lynn Classical

</DESCRIPTION></DESCRIPTION>

</PROGRAMSLOT></PROGRAMSLOT>

Page 42: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A First Document: A First Document: TVSCHEDULE.XMLTVSCHEDULE.XML

<?xml version="1.0"?>

<TVSCHEDULE NAME="Salem Access Television"><CHANNEL CHAN="3">

<BANNER>Channel 3 Program Schedule</BANNER>

<DAY><DATE>Monday, May 24th</DATE><PROGRAMSLOT><TIME>3:00 PM</TIME><TITLE>Salem High Basketball</TITLE><DESCRIPTION>vs. Lynn Classical</DESCRIPTION></PROGRAMSLOT>...

Page 43: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XML requirementsXML requirements

HTML’s requirements for markup are rather loose, HTML’s requirements for markup are rather loose, allowing end tags to be omitted (such as allowing end tags to be omitted (such as </p></p>))

To make XML easier to parse, markup standards To make XML easier to parse, markup standards have to be strictly enforcedhave to be strictly enforced

Namely, all XML documents must be Namely, all XML documents must be well-formedwell-formed or or validvalid

Also, unlike HTML, Also, unlike HTML, whitespace is preservedwhitespace is preserved!!

Page 44: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Well-Formed XMLWell-Formed XML

All XML documents All XML documents mustmust start with this declaration: start with this declaration:

<?xml version=“1.0”?><?xml version=“1.0”?> All tags must be closed:All tags must be closed:

<DESCRIPTION>SHS vs. <DESCRIPTION>SHS vs. Brookline</DESCRIPTION>Brookline</DESCRIPTION>

Empty tags are written like this:Empty tags are written like this:

<br /><br /> Tags are Tags are case-sensitive!case-sensitive!

Page 45: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Valid XMLValid XML

XML documents can also be XML documents can also be validvalid To be valid, XML documents must have a document To be valid, XML documents must have a document

type definition (DTD), and they must conform to the type definition (DTD), and they must conform to the rules in that DTD.rules in that DTD.

Valid XML has a declaration like this:Valid XML has a declaration like this:<!DOCTYPE TVSCHEDULE SYSTEM "tvschedule.dtd”><!DOCTYPE TVSCHEDULE SYSTEM "tvschedule.dtd”>

Valid XML documents must Valid XML documents must alsoalso be well-formed be well-formed

Page 46: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Document Type Definitions Document Type Definitions (DTD)’s(DTD)’s DTD’s define the DTD’s define the content modelcontent model of an XML file, of an XML file,

namely, which tags are valid in a given contextnamely, which tags are valid in a given context If you’ve ever validated HTML for your website, you If you’ve ever validated HTML for your website, you

probably know about DTD’sprobably know about DTD’s DTD writing can be difficult, but there are online DTD DTD writing can be difficult, but there are online DTD

generators that work from your XML files that will give generators that work from your XML files that will give you a useable DTD.you a useable DTD.

Page 47: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

TVSCHEDULE.DTDTVSCHEDULE.DTD

<!ELEMENT TVSCHEDULE (CHANNEL+)>

<!ATTLIST TVSCHEDULE

NAME CDATA #REQUIRED>

<!ELEMENT CHANNEL (BANNER, DAY+)>

<!ATTLIST CHANNEL

CHAN CDATA #REQUIRED>

<!ELEMENT BANNER (#PCDATA)>

<!ELEMENT

DAY ((DATE, HOLIDAY) | (DATE, PROGRAMSLOT+))+>

<!ELEMENT HOLIDAY (#PCDATA)>

<!ELEMENT DATE (#PCDATA)>

Page 48: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

TVSCHEDULE.DTD TVSCHEDULE.DTD ContinuedContinued

<!ELEMENT PROGRAMSLOT (TIME, TITLE, DESCRIPTION?)>

<!ATTLIST PROGRAMSLOT

VTR CDATA #IMPLIED>

<!ELEMENT TIME (#PCDATA)>

<!ELEMENT TITLE (#PCDATA)>

<!ATTLIST TITLE RATING CDATA #IMPLIED

LANGUAGE CDATA #IMPLIED

LIVE CDATA #IMPLIED

NEW CDATA #IMPLIED>

<!ELEMENT DESCRIPTION (#PCDATA)>

Page 49: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Special Characters: EntitiesSpecial Characters: Entities

As with HTML, there are special characters that can’t As with HTML, there are special characters that can’t be used in text:be used in text:

<<, , >>, , ‘‘, , ““, , && These characters are represented by These characters are represented by entitiesentities

– << and and >> are represented as are represented as &lt&lt;; and and &gt;&gt;, just as in HTML, just as in HTML– &&, , ““ and and ‘‘ are represented by are represented by &amp&amp;, ;, &quot&quot; and ; and &apos&apos;;

XML lets you define your own entities, such as XML lets you define your own entities, such as &satv&satv;; for “Salem Access Television” for “Salem Access Television”

<!ENTITY satv <!ENTITY satv “Salem Access Television”“Salem Access Television”>>

Page 50: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

AttributesAttributes

You know attributes from HTML: They modify You know attributes from HTML: They modify information in a tag, such as:information in a tag, such as:<IMG SRC=<IMG SRC=“ball.gif”“ball.gif” LENGTH= LENGTH=“100”“100” WIDTH=WIDTH=“100”“100”>>

XML allows attributes as well, likeXML allows attributes as well, like<TVSCHEDULE NAME=<TVSCHEDULE NAME=“Salem Access “Salem Access Television”Television”>>

In XML, all attributes In XML, all attributes mustmust be in quotes. be in quotes.

Page 51: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Editing XMLEditing XML

Editors you may hear about include Editors you may hear about include EXMLEXML, , XMLEXMLE, , XML SpyXML Spy and and psgmlpsgml for Emacs. for Emacs.

Most XML editors now available are primitive Most XML editors now available are primitive and cumbersome to use.and cumbersome to use.

You can, of course, use Notepad or any plain You can, of course, use Notepad or any plain text editor for XML just as with HTMLtext editor for XML just as with HTML

You most likely will use a front end to convert You most likely will use a front end to convert your application’s data to XMLyour application’s data to XML

Page 52: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Editing XML Example: EXMLEditing XML Example: EXML

Page 53: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Viewing XML in Internet Viewing XML in Internet Explorer 5Explorer 5

Page 54: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XSL—A Transformation and XSL—A Transformation and Styling languageStyling language XSL is a XSL is a transformationtransformation language that works language that works

by pattern matchingby pattern matching A pattern can be an element name, or A pattern can be an element name, or

wildcard expressionwildcard expression When patterns are matched, tags and text When patterns are matched, tags and text

are output according to markup.are output according to markup.

Page 55: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

TVSCHEDULEHTML.XSLTVSCHEDULEHTML.XSL

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="DAY/PROGRAMSLOT">

<!—Output time and program title —>

<xsl:value-of select="TIME"/>: <xsl:value-of select="TITLE"/>

<!— Include optional DESCRIPTION and RATING items —>

<xsl:if test="DESCRIPTION">

<em><strong><xsl:value-of select="DESCRIPTION"/></strong></em></xsl:if>

<br />

<xsl:if test="TITLE/@RATING">

<em>Rating: <xsl:value-of select="TITLE/@RATING"/></em><br />

</xsl:if>

</xsl:template>

Page 56: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

How XSL worksHow XSL works

The The templatetemplate markup matches PROGRAMSLOT tags markup matches PROGRAMSLOT tags that occur inside DAY tagsthat occur inside DAY tags<xsl:template match=<xsl:template match="DAY/PROGRAMSLOT""DAY/PROGRAMSLOT">>

Value-ofValue-of tags return the contents of a tag, in this case, tags return the contents of a tag, in this case,

the NAME attribute inside TVSCHEDULEthe NAME attribute inside TVSCHEDULE <xsl:value-of select=<xsl:value-of select="/TVSCHEDULE/@NAME""/TVSCHEDULE/@NAME"/>/>

The If tag renders its contents if a condition is met:<xsl:if test=<xsl:if test="DESCRIPTION""DESCRIPTION">>

XML documents link to their XSL stylesheets with: <?<?xml-stylesheet type="text/xsl" xml-stylesheet type="text/xsl" href="tvschedulehtml.xsl"?>href="tvschedulehtml.xsl"?>

Page 57: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

TVSCHEDULE styled with TVSCHEDULE styled with XSLXSL

Page 58: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Some XSL Processors:Some XSL Processors:

XTXT — James Clark’s XSL processor, in Java — James Clark’s XSL processor, in Java LotusXSLLotusXSL — Java-based XSL processor, with — Java-based XSL processor, with

sourcesource All of these processors will run on Windows, All of these processors will run on Windows,

Mac & LinuxMac & Linux

Page 59: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Things to keep in mind about XSLThings to keep in mind about XSL

XSL is a moving target—there have been numerous XSL is a moving target—there have been numerous changes since it was first proposed two years ago changes since it was first proposed two years ago and it’s not done yet.and it’s not done yet.

IE 5 supports the December ‘98 XSL draft but IE 5 supports the December ‘98 XSL draft but notnot the the current April ‘99 draftcurrent April ‘99 draft

You may need two different XSL stylesheets for IE5 You may need two different XSL stylesheets for IE5 and any other processor, until a service pack is and any other processor, until a service pack is releasedreleased

Page 60: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XHTML: Your first taste of XMLXHTML: Your first taste of XML

XHTML 1.0 is a version of HTML 4.0 rewritten XHTML 1.0 is a version of HTML 4.0 rewritten in terms of XML instead of SGML, as with in terms of XML instead of SGML, as with present HTMLpresent HTML

Works just like HTMLWorks just like HTML

Some syntax has been changed to make it Some syntax has been changed to make it XML-compatible.XML-compatible.

Page 61: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Why use XHTML?Why use XHTML?

XHTML is readable with all current browsers XHTML is readable with all current browsers (with the exception of some older Mac (with the exception of some older Mac browsers)browsers)

XHTML is made for extensibility in mindXHTML is made for extensibility in mind

XHTML can take advantage of the many tools XHTML can take advantage of the many tools now available for XMLnow available for XML

Page 62: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

How do I use XHTML?How do I use XHTML?

Your code should be clean HTML. The messier it is, Your code should be clean HTML. The messier it is, the harder it will be to convert.the harder it will be to convert.

Closing tags—like Closing tags—like </p></p> and and </li></li> are are mandatorymandatory. .

Tags are now in Tags are now in lower-caselower-case!!

Unlike HTML, whitespace is important.Unlike HTML, whitespace is important.

The conversion tool The conversion tool TidyTidy from the W3C can from the W3C can automatically convert your pages to XHTML and fix automatically convert your pages to XHTML and fix any style problemsany style problems

Page 63: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XML For ProgrammersXML For Programmers

XML development software exists for many major XML development software exists for many major languages, including Perl, Python, C++, Visual Basic languages, including Perl, Python, C++, Visual Basic and others.and others.

But almost all development in XML first starts with But almost all development in XML first starts with Java, with more XML tools available in this language Java, with more XML tools available in this language than any other.than any other.

Page 64: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XML Parsers XML Parsers

A A parserparser is a program that will read a file and extract is a program that will read a file and extract information that can be understood by humans, or information that can be understood by humans, or other softwareother software

For XML, there are two different kinds of parsers: For XML, there are two different kinds of parsers: SAX parsers and DOM parsersSAX parsers and DOM parsers

Each does the same thing, but both work differently.Each does the same thing, but both work differently. Both SAX and DOM have become de facto standards Both SAX and DOM have become de facto standards

Page 65: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

SAXSAX: : Event-driven XML parser APIEvent-driven XML parser API SAX: SAX: SSimple imple AAPI for PI for XXMLML Designed by David Megginson of MicrostarDesigned by David Megginson of Microstar SAX is implemented by SAX is implemented by ÆlfredÆlfred, , XML4JXML4J, and , and

DCXJPDCXJP.. SAX is designed to be compact and easily SAX is designed to be compact and easily

implemented.implemented.

Page 66: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

How SAX worksHow SAX works

SAX is SAX is event-drivenevent-driven SAX reads your input XML document and SAX reads your input XML document and

sends events to your application that sends events to your application that correspond to opening elements, text, correspond to opening elements, text, whitespace and closing elements, among whitespace and closing elements, among othersothers

Page 67: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

SAX Diagram SAX Diagram

XML Document Your ProgramXML Document Your Program<DAY><DATE>Monday, May 24th</DATE>

<PROGRAMSLOT>

<TIME>3:00 PM</TIME>

<TITLE>Salem High Basketball</TITLE>

...

</PROGRAMSLOT>

startElement (“DAY”)...

characters(“Monday May 24th”)

startElement(“PROGRAMSLOT”)...

startElement(“TIME”)...

startElement(“TITLE”)characters(“Salem High

Basketball”)endElement(“TITLE”)

...endElement(“PROGRAMSLOT”)

Page 68: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Using SAX to read XMLUsing SAX to read XML

To use SAX, you create an instance of a parser To use SAX, you create an instance of a parser object that’s pointed to your document and to your object that’s pointed to your document and to your app.app.

While SAX reads the document, it calls these While SAX reads the document, it calls these methods in your app as it goes :methods in your app as it goes :– startElementstartElement: Start tag: Start tag– endElementendElement: End tag: End tag– characterscharacters: Text data: Text data

Error handling is supported, tooError handling is supported, too

Page 69: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

The Document Object Model: The Document Object Model: A W3C StandardA W3C Standard The Document Object Model (DOM) is a standard The Document Object Model (DOM) is a standard

API, from the W3C (the World Wide Web API, from the W3C (the World Wide Web Consortium), for programs that need to manipulate Consortium), for programs that need to manipulate HTML and XML documents.HTML and XML documents.

Unlike SAX, the DOM builds a tree of nodes, Unlike SAX, the DOM builds a tree of nodes, corresponding to elements, attributes and text.corresponding to elements, attributes and text.

The DOM is now standard in many browsers, and The DOM is now standard in many browsers, and supported by IBM’s supported by IBM’s XML4JXML4J and Datachannel’s and Datachannel’s DCXJPDCXJP..

Page 70: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A DOM TreeA DOM Tree

TVSCHEDULE

CHANNEL CCHANNEL

DAY DATE

PROGRAMSLOTTITLE “Foresight”

“Fri, June 26th”

...

Page 71: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

DOM Diagram DOM Diagram

Your ProgramYour Program XML FileXML FilegetDocumentElement

…getAttributes.FirstChild

getChildNodes

if (GetNodeName.equals(“CHANNEL”))

getChildNodes…

if GetNodeName.equals(“DAY”)

…GetFirstChild.getNodeValue

<TVSCHEDULE NAME=“SATV”>

…<CHANNEL CHAN=“3”>

<DAY>

<DATE>June 23rd, 1999</DATE>

Page 72: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Using the DOM to read XMLUsing the DOM to read XML

To use the DOM, you first create an To use the DOM, you first create an instanceinstance of the of the document.document.

You then use method calls to traverse the document You then use method calls to traverse the document tree, for example:tree, for example:– getDocumentElementgetDocumentElement gets the root gets the root – getChildNodesgetChildNodes gets all child nodes gets all child nodes– getAttributes getAttributes gets attributesgets attributes– getNodeNamegetNodeName gets the name of an element gets the name of an element– getNodeValuegetNodeValue gets the content of an element gets the content of an element

Page 73: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Some XML Parsers in JavaSome XML Parsers in Java

XML4JXML4J — Parser from IBM’s Alphaworks division. — Parser from IBM’s Alphaworks division. Supports both SAX and DOMSupports both SAX and DOM

ÆlfredÆlfred — Compact parser that supports SAX; ideal — Compact parser that supports SAX; ideal for Java appletsfor Java applets

DCXJPDCXJP — Datachannel’s XML parser. Supports both — Datachannel’s XML parser. Supports both SAX and DOM and is used in Internet Explorer 5. SAX and DOM and is used in Internet Explorer 5. Also supports XSLAlso supports XSL

Sun is working on XML support for JavaSun is working on XML support for Java

Page 74: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

A Example Application: A Example Application: ScXMLScXML ScXMLScXML is a Java application that reads the is a Java application that reads the

TVSCHEDULE file described earlier and converts it TVSCHEDULE file described earlier and converts it into Scala Lingua™ script code to display on SATV’s into Scala Lingua™ script code to display on SATV’s bulletin boardbulletin board

ScXMLScXML is template based so that staff can design is template based so that staff can design

pages right on the Scala, without knowing Javapages right on the Scala, without knowing Java..

Page 75: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

ScXML ScreenshotScXML Screenshot

Page 76: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

XML Standards: What’s next?XML Standards: What’s next?

XSL has been split up into two different standards, XSL has been split up into two different standards, XSLT, for transformation and FO (flow objects) for XSLT, for transformation and FO (flow objects) for formatting. Expect changes.formatting. Expect changes.

DOM and SAX are firm standards; both will be DOM and SAX are firm standards; both will be updated by the end of the year.updated by the end of the year.

XHTML will likely be a standard by the end of the XHTML will likely be a standard by the end of the year.year.

There are many other XML features not mentioned There are many other XML features not mentioned here, including Xlink/Xpointer, that will make here, including Xlink/Xpointer, that will make document handling and linking much easier.document handling and linking much easier.

Page 77: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

SMIL—A Hidden Ally for SMIL—A Hidden Ally for Public AccessPublic Access SMIL — Synchronized SMIL — Synchronized MMultimedia ultimedia IIntegration ntegration

LLanguage is an XML-based language that’s used to anguage is an XML-based language that’s used to integrate multimedia, audio & video presentations.integrate multimedia, audio & video presentations.

Supported by Real Networks G2 PlayerSupported by Real Networks G2 Player It supports closed captioning and ancillary text data It supports closed captioning and ancillary text data

as wellas well This is a This is a VERY VERY important development for public important development for public

accessaccess

Page 78: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Conclusion: What you need to Conclusion: What you need to know to use XML at your centerknow to use XML at your center Survey data in your organization Survey data in your organization What information needs to be shared?What information needs to be shared? XML will not replace databases, but it can make it XML will not replace databases, but it can make it

easier for applications to use databases.easier for applications to use databases. XML is at its best when it is used to transfer data to XML is at its best when it is used to transfer data to

many different apps.many different apps. Consider SMIL—it could be very important if you plan Consider SMIL—it could be very important if you plan

on streaming video.on streaming video.

Page 79: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Resources and Further Resources and Further InformationInformation The XML for Video website has links to all resources The XML for Video website has links to all resources

mentioned in this presentation:mentioned in this presentation:http://www1.shore.net/~dmoisan/comp/http://www1.shore.net/~dmoisan/comp/

videoxml.htmlvideoxml.html This site will be updated regularly with new software This site will be updated regularly with new software

and documentsand documents An email list will be up and running shortly after the An email list will be up and running shortly after the

convention; watch for detailsconvention; watch for details

Page 80: Java & XML for Public Access Television Advanced Internet Issues David Moisan July 9th, 1999

Acknowledgements & CreditsAcknowledgements & Credits

Some Java examples are courtesy of Some Java examples are courtesy of Java in A Java in A Nutshell 2nd EditionNutshell 2nd Edition, David Flanagan, O’Reilly & , David Flanagan, O’Reilly & Associates, 1998 (Associates, 1998 (http://www.ora.comhttp://www.ora.com))

People who helped: Rick Hayes of Miami Valley People who helped: Rick Hayes of Miami Valley Cable Council, Jennifer Krebs, of the City of Cable Council, Jennifer Krebs, of the City of Enumclaw, WA, & Jen Casco of Salem Access TVEnumclaw, WA, & Jen Casco of Salem Access TV

Presentation equipment courtesy MVCC & Meeting Presentation equipment courtesy MVCC & Meeting Points, Inc.Points, Inc.

©1999 David Moisan. Permission is granted to reproduce this ©1999 David Moisan. Permission is granted to reproduce this presentation for any purpose as long as this notice remains intact.presentation for any purpose as long as this notice remains intact.