EXtensible Markup Language (XML) James Atlas July 15, 2008.

Slides:



Advertisements
Similar presentations
XML-XSL Introduction SHIJU RAJAN SHIJU RAJAN Outline Brief Overview Brief Overview What is XML? What is XML? Well Formed XML Well Formed XML Tag Name.
Advertisements

J0 1 Marco Ronchetti - Web architectures – Laurea Specialistica in Informatica – Università di Trento Java XML parsing.
The Java Platform and XML Portable Code, Portable Data James Duncan Davidson Staff Engineer, Sun Microsystems, Inc.
XML: Extensible Markup Language
SDPL 2002Notes 3: XML Processor Interfaces1 3.3 JAXP: Java API for XML Processing n How can applications use XML processors? –A Java-based answer: through.
31 Signs That Technology Has Taken Over Your Life: #6. When you go into a computer store, you eavesdrop on a salesperson talking with customers -- and.
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.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
Tutorial 11 Creating XML Document
Document Type Definitions. XML and DTDs A DTD (Document Type Definition) describes the structure of one or more XML documents. Specifically, a DTD describes:
MC 365 – Software Engineering Presented by: John Ristuccia Shawn Posts Ndi Sampson XSLT Introduction BCi.
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.
1 CS122B: Projects in Databases and Web Applications Spring 2015 Notes 05: XML Professor Chen Li Department of Computer Science UC Irvine CS122BNotes 05:
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools Leonidas Fegaras.
Pemrograman Berbasis WEB XML part 2 -Aurelio Rahmadian- Sumber: w3cschools.com.
SDPL 2003Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
Introduction to XML cs3505. References –I got most of this presentation from this site –O’reilly tutorials.
1 XML at a neighborhood university near you Innovation 2005 September 16, 2005 Kwok-Bun Yue University of Houston-Clear Lake.
School of Computing and Management Sciences © Sheffield Hallam University To understand the Oracle XML notes you need to have an understanding of all these.
Representing Web Data: XML CSI 3140 WWW Structures, Techniques and Standards.
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.
XML What is XML? XML v.s. HTML XML Components Well-formed and Valid Document Type Definition (DTD) Extensible Style Language (XSL) SAX and DOM.
XML 1 Enterprise Applications CE00465-M XML. 2 Enterprise Applications CE00465-M XML Overview Extensible Mark-up Language (XML) is a meta-language that.
SAX Parsing Presented by Clifford Lemoine CSC 436 Compiler Design.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 6 XSLT (Based on Møller and Schwartzbach,
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.
Advanced Java Session 9 New York University School of Continuing and Professional Studies.
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.
SDPL 2002Notes 3: XML Processor Interfaces1 3. XML Processor APIs n How can applications manipulate structured documents? –An overview of document parser.
 XML is designed to describe data and to focus on what data is. HTML is designed to display data and to focus on how data looks.  XML is created to structure,
Intro. to XML & XML DB Bun Yue Professor, CS/CIS UHCL.
Processing of structured documents Spring 2002, Part 2 Helena Ahonen-Myka.
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.
Electronic Commerce COMP3210 Session 4: Designing, Building and Evaluating e-Commerce Initiatives – Part II Dr. Paul Walcott Department of Computer Science,
1 Tutorial 13 Validating Documents with DTDs Working with Document Type Definitions.
1 XSLT An Introduction. 2 XSLT XSLT (extensible Stylesheet Language:Transformations) is a language primarily designed for transforming the structure of.
ECA 228 Internet/Intranet Design I XSLT Example. ECA 228 Internet/Intranet Design I 2 CSS Limitations cannot modify content cannot insert additional text.
Softsmith Infotech XML. Softsmith Infotech XML EXtensible Markup Language XML is a markup language much like HTML Designed to carry data, not to display.
XML Processing in Java. Required tools Sun JDK 1.4, e.g.: JAXP (part of Java Web Services Developer Pack, already in Sun.
Java API for XML Processing (JAXP) Dr. Rebhi S. Baraka Advanced Topics in Information Technology (SICT 4310) Department of Computer.
Sheet 1XML Technology in E-Commerce 2001Lecture 3 XML Technology in E-Commerce Lecture 3 DOM and SAX.
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.
XML Instructor: Charles Moen CSCI/CINF XML  Extensible Markup Language  A set of rules that allow you to create your own markup language  Designed.
Lecture 16 Introduction to XML Boriana Koleva Room: C54
Chapter 27 The World Wide Web and XML. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.27-2 Topics in this Chapter The Web and the Internet.
CSE 6331 © Leonidas Fegaras XML Tools1 XML Tools.
XML and SAX (A quick overview) ● What is XML? ● What are SAX and DOM? ● Using SAX.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 4 1COMP9321, 15s2, Week.
Web Technologies Lecture 4 XML and XHTML. XML Extensible Markup Language Set of rules for encoding a document in a format readable – By humans, and –
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.
1 Introduction JAXP. Objectives  XML Parser  Parsing and Parsers  JAXP interfaces  Workshops 2.
Martin Kruliš by Martin Kruliš (v1.1)1.
SDPL 20063: XML Processor Interfaces1 3. XML Processor APIs n How can (Java) applications manipulate structured (XML) documents? –An overview of XML processor.
C Copyright © 2011, Oracle and/or its affiliates. All rights reserved. Introduction to XML Standards.
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.
Jackson, Web Technologies: A Computer Science Perspective, © 2007 Prentice-Hall, Inc. All rights reserved Chapter 7 Representing Web Data:
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
Extensible Markup Language (XML) Pat Morin COMP 2405.
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Unit 4 Representing Web Data: XML
XML in Web Technologies
Chapter 7 Representing Web Data: XML
XML Parsers Overview Types of parsers Using XML parsers SAX DOM
Java API for XML Processing
Presentation transcript:

eXtensible Markup Language (XML) James Atlas July 15, 2008

James Atlas - CISC3702 Announcements Project 1 due Thursday Project 1 due Thursday Office hours: Office hours: Tues 3:30-4:30, Wed 11-12, Thurs 3:30-4:30 Tues 3:30-4:30, Wed 11-12, Thurs 3:30-4:30

July 15, 2008James Atlas - CISC3703 Review Multithreaded Programming Multithreaded Programming Network Programming Network Programming

July 15, 2008James Atlas - CISC3704 Quiz

July 15, 2008James Atlas - CISC3705 Using the Synchronized Keyword Can use synchronized keyword inside of methods Can use synchronized keyword inside of methods synchronized { // atomic operation }  Implies synchronization on this object  Same rules as synchronized method access Only one thread in synchronized code at a time Only one thread in synchronized code at a time

July 15, 2008James Atlas - CISC3706 Using the Synchronized Keyword Alternatively, can use to synchronize access to an object Alternatively, can use to synchronize access to an object synchronized (sharedObject) { synchronized (sharedObject) { // atomic operation // atomic operation}  Same rules as synchronized method access Equivalent code blocks: Equivalent code blocks: synchronized (this) { // atomic operation // atomic operation} synchronized { // atomic operation // atomic operation}

July 15, 2008James Atlas - CISC3707 XML Motivation Motivation XML and Java XML and Java  parsing  generation  translation

July 15, 2008James Atlas - CISC3708 What is XML? eXtensible Markup Language eXtensible Markup Language Describes data in a textual, hierarchical (tree- based) structure Describes data in a textual, hierarchical (tree- based) structure  Structure, store, and transmit information  Portable: preserves meaning and structure across machines/platforms Doesn’t do anything itself Doesn’t do anything itself  Other applications use XML to share information

July 15, 2008James Atlas - CISC3709 What is XML? Simplified subset of Standard Generalized Markup Language (SGML) Defines other languages, such as RSS   Get updates on your favorite web sites Like well-structured HTML Like well-structured HTML Different focus from HTML   XML: focuses on describing information   HTML: focuses on displaying information, how data looks

July 15, 2008James Atlas - CISC37010 One Use of XML Transmit messages across network Transmit messages across network Client Server Network 4*2 + 3*4 20

July 15, 2008James Atlas - CISC37011 Java and XML Java class libraries to read, parse, validate, generate, and transform XML data Java class libraries to read, parse, validate, generate, and transform XML data

July 15, 2008James Atlas - CISC37012 XML Documents All text All text  makes it relatively easy for humans (and programs) to create, examine, and debug them Syntax rules Syntax rules  Very strict  Very simple  Make document easy to parse Case-sensitive Case-sensitive The ML of “Markup Language” The ML of “Markup Language”  Tags, enclosed in angle brackets,  Tags, enclosed in angle brackets,

July 15, 2008James Atlas - CISC37013 XML Tags Identify data using tags Identify data using tags  called elements <name> Place content between tags: Jack Sparrow Place content between tags: Jack Sparrow Tags can have attributes, like this: Jack Sparrow Tags can have attributes, like this: Jack Sparrow Tags can contain child elements   Jack Sparrow

July 15, 2008James Atlas - CISC37014 Examples of XML Syntax Elements/Tags: 22 May Elements/Tags: 22 May Attributes: 5:57:39 7:57:39 Attributes: 5:57:39 7:57:39 Comments: Comments: Entity References &otherLoc; &copyr; &LegalDisclaimer; Entity References &otherLoc; &copyr; &LegalDisclaimer; Document type reference Document type reference “Empty” tag Either “” or ‘’ Need to be declared previously Describes doc’s structure

July 15, 2008James Atlas - CISC37015 Well-Formedness All documents must be well-formed All documents must be well-formed  Each tag must have a corresponding end tag Jack Sparrow Jack Sparrow  Or, the tag must be self-contained Start Tag for a Name piece of data Corresponding End tag

July 15, 2008James Atlas - CISC37016 XML Syntax Example <mail> Assignment due Assignment due CISC370 CISC370 Please see me for extra help Please see me for extra help </mail> Prolog/Declaration DOCTYPE reference root Viewing in Eclipse

July 15, 2008James Atlas - CISC37017 XML Syntax Example mail message tofrom body Assignment due type=text/plain Importance=high tofrom subjectbody CISC370 Please see me for extra help unread Can have only one root attribute

July 15, 2008James Atlas - CISC37018 XML Syntax: Escape Codes < less than sign < < less than sign < > greater than sign > > greater than sign > & ampersand & & ampersand & " quote " " quote " &apos; apostrophe ’ &apos; apostrophe ’

July 15, 2008James Atlas - CISC37019 XML Design Considerations When to use attributes and when to use child elements? When to use attributes and when to use child elements? Elements Elements  Best for “things”, particularly those that have properties  Easier to extend later Attributes Attributes  Best for properties, like modifiers or units

July 15, 2008James Atlas - CISC37020 XML Structure Specifications XML documents that do not have some kind of specification can contain any tags XML documents that do not have some kind of specification can contain any tags  makes standardized communication very hard! Most XML documents obey a particular set of rules as to their structure Most XML documents obey a particular set of rules as to their structure  Rules define what tags, attributes, and entities may appear in the document XML documents can use namespaces, which are separate scopes within which tags are defined XML documents can use namespaces, which are separate scopes within which tags are defined  similar to namespaces in C++

July 15, 2008James Atlas - CISC37021 Specifying Valid XML Tags Document Type Definition (DTD) Document Type Definition (DTD)  Written in SGML (which has a very confusing syntax!)  DTD approach is not used very much anymore Schema Schema  Current approach  Written in XML Makes it much easier to define the structure of an XML document Makes it much easier to define the structure of an XML document

July 15, 2008James Atlas - CISC37022 XML Programming Generally, programs (and programmers) deal with XML in one of three ways Generally, programs (and programmers) deal with XML in one of three ways  Parsing: XML document as program input Given an XML document, extract the stored data and process it programmatically Given an XML document, extract the stored data and process it programmatically  Generation: XML doc as program output Given some data, generate an XML representation of it Given some data, generate an XML representation of it  Transformation: XML doc as both program input and output Given an XML document, transform it into some other kind of document Given an XML document, transform it into some other kind of document

July 15, 2008James Atlas - CISC37023 Java XML Programming Java APIs for XML Processing (JAXP) Java APIs for XML Processing (JAXP)  included with Java 1.4 and later  APIs make programmatically working with XML under Java very easy and straightforward  Sun’s collection of XML APIs Other packages available, which all work a little differently Other packages available, which all work a little differently  Just a library of classes and methods 

July 15, 2008James Atlas - CISC37024 Fundamental Models for XML Parsing SAX - Simple API for XML SAX - Simple API for XML  Serial, sequential access to XML tags and content  event-oriented callback model  fast and low overhead  difficult to use for transforms DOM - Document Object Model for XML DOM - Document Object Model for XML  Tree-based access to entire XML document  data traversal model  keeps entire document in memory  easy to use for transforms

July 15, 2008James Atlas - CISC37025 The SAX Programming Model Serial Access with the Simple API for XML   Requires more programming   Event-driven   Harder to visualize A SAX Parser chops an XML document into a sequence of events A SAX Parser chops an XML document into a sequence of events  Event: encountering an element of the XML document  Parser delivers XML events and errors, if any occur, to application by calling methods on handler objects (provided by program)

July 15, 2008James Atlas - CISC37026 The SAX Programming Model Handler objects must implement particular interfaces: Handler objects must implement particular interfaces:  org.xml.sax.ContentHandler for receiving events about document contents and tags  org.xml.sax.ErrorHandler for receiving errors and warnings that occur during parsing  org.xml.sax.DTDHandler  org.xml.sax.EntityResolver

July 15, 2008James Atlas - CISC37027 SAX Parsers Most SAX parsers can read XML data from any valid java.io.Reader Most SAX parsers can read XML data from any valid java.io.Reader  Why a Reader instead of an InputStream? or directly from a URL (for directly parsing XML that exists on the Internet) or directly from a URL (for directly parsing XML that exists on the Internet) SAX parsers can be validating or non- validating SAX parsers can be validating or non- validating  Validation: checking a document for conformance to its specified DTD or schema  Most SAX parsers support both operational modes

July 15, 2008James Atlas - CISC37028 SAX Programming – Event Passing SAX Parser Content Handler startDocument endDocument startElement endElement characters Locator setDocumentLocator Input Reader Locator: an object that keeps track of the current position in the document Callback methods Subclass of org.xml.sax.helpers.DefaultHandler

July 15, 2008James Atlas - CISC37029 SAX Programming – Basics To use SAX, you need to import the relevant packages, e.g., To use SAX, you need to import the relevant packages, e.g.,  import org.xml.sax.*;  import org.xml.sax.helpers.*;  import javax.xml.parsers.*; To do parsing, you need a SAX XMLReader object To do parsing, you need a SAX XMLReader object SAXParserFactory sp_factory = SAXParserFactory.newInstance(); SAXParserFactory sp_factory = SAXParserFactory.newInstance(); SAXParser sp = sp_factory.newSAXParser(); XMLReader theParser = sp.getXMLReader();

July 15, 2008James Atlas - CISC37030 SAX Programming – Errors SAX Parser can encounter three kinds of errors during parsing: SAX Parser can encounter three kinds of errors during parsing:  warninga non-serious problem occurred  errora serious but recoverable problem occurred  fatalErrora problem occurred that is so grave that parsing cannot continue. Warning and error conditions result from violation of document validation (DTD or schema constraints) Warning and error conditions result from violation of document validation (DTD or schema constraints) FatalError conditions are from I/O problems or non-well-formed XML FatalError conditions are from I/O problems or non-well-formed XML Not all SAX parsers treat each condition in the same category   Check the docs! All SAX parsers can throw SAXExceptions All SAX parsers can throw SAXExceptions  Any SAX handler method (the methods the parser calls on your handler object) can also throw a SAXException Parsing can continue

July 15, 2008James Atlas - CISC37031 SAX Programming – Example Example program consists of two classes: Example program consists of two classes:  SAXExample supplies a main() method that creates a SAX parser and invokes it to parse a file specified on the command line supplies a main() method that creates a SAX parser and invokes it to parse a file specified on the command line  SAXHandler acts as the SAX ContentHandler and ErrorHandler acts as the SAX ContentHandler and ErrorHandler

July 15, 2008James Atlas - CISC37032 SAX Programming – Example 1import java.io.*; 2import org.xml.sax.*; 3import org.xml.sax.helpers.*; 4import javax.xml.parsers.*; 5 6public class SAXExample { 7 public static void main(String [] args) { 8 try { 9 System.out.println("Creating and setting up the SAX parser."); 10 SAXParserFactory sp_factory = SAXParserFactory.newInstance(); 11 XMLReader theReader = sp_factory.newSAXParser().getXMLReader(); 12 SAXHandler theHandler = new SAXHandler(); 13 theReader.setContentHandler(theHandler); 14 theReader.setErrorHandler(theHandler); 15 theReader.setFeature(" false); 16 System.out.println("Making InputSource for " + args[0]); 17 FileReader file_in = new FileReader(args[0]); 18 System.out.println("About to parse...”); 19 theReader.parse(new InputSource(file_in)); 20 System.out.println("...parsing done."); 21 } catch (Exception e) { 22 System.err.println("Error: " + e); e.printStackTrace(); 23 } 24 } 25} Can call parse with other args

July 15, 2008James Atlas - CISC37033 SAX Programming – Example 1import org.xml.sax.*; 2 3public class SAXHandler implements ContentHandler, ErrorHandler 5{ 6 private Locator loc = null; 7 8 public void setDocumentLocator(Locator l) { 9 loc = l; 10 } public void characters(char [] ch, int st, int len) { 13 String s = new String(ch, st, len); 14 System.out.println("Got content string '" + s + "'"); 15 return; 16 } public void startElement(String uri, String lname, 19 String qname, Attributes attrs) { 20 System.out.print(lname + " tag with "); 21 System.out.print(attrs.getLength() + " attrs starts"); 22 System.out.println(" at line " + loc.getLineNumber()); 23 } 24 Called when a set of characters is encountered Called when a starting element tag is encountered

July 15, 2008James Atlas - CISC37034 SAX Programming – Example 25 public void endElement(String uri, String lname, String qname) { 26 System.out.print(lname + " tag ends "); 27 System.out.println("at line " + loc.getLineNumber()); 28 } public void startDocument() { } 31 public void endDocument() { } 32 public void processingInstruction(String t, String d) { } 33 public void skippedEntity(String name) { } 34 public void ignorableWhitespace(char[] ch, int st, int len) { } 35 public void startPrefixMapping(String p, String uri) { } 36 public void endPrefixMapping(String p) { } public void warning(SAXParseException e) { 39 System.err.print("SAX Warning: " + e); 40 System.err.println(" at line " + loc.getLineNumber()); 41 } 42 public void error(SAXParseException e) { 44 System.err.print("SAX Error: " + e); 45 System.err.println(" at line " + loc.getLineNumber()); 46 } public void fatalError(SAXParseException e) { 49 System.err.print("SAX Fatal Error: " + e); 50 System.err.println(" at line " + loc.getLineNumber()); 51 } 52} Called when a SAX warning is encountered Called when a SAX error is encountered Called when a SAX fatal error is encountered Called when an ending element tag is encountered Called when the start or end of the doc is encountered

July 15, 2008James Atlas - CISC37035 DOM Programming – Overview DOM parser builds an in-memory tree representation of the entire XML document DOM parser builds an in-memory tree representation of the entire XML document  reference to tree is returned to your program DOM tree is composed of objects, most of which implement the following interfaces from the org.w3c.dom package: DOM tree is composed of objects, most of which implement the following interfaces from the org.w3c.dom package:  Node parent interface of all DOM tree nodes  Element represents a tag in a XML document, may have children  Document represents an entire XML document, always has children  Text contents of an element or an attribute  Attr represents an attribute of an element

July 15, 2008James Atlas - CISC37036 DOM Programming – Overview Your program can manipulate the DOM tree Your program can manipulate the DOM tree  Traverse, modify, print, apply XSL transforms (XML Stylesheet Language Transforms … more about that in a bit), and many more functions Most DOM parsers allow either validation or non-validation modes Most DOM parsers allow either validation or non-validation modes  Validation refers to checking for conformance against the document’s specified DTD or schema

July 15, 2008James Atlas - CISC37037 Document Builder DOM Programming – Model Parser Input Reader DTD or schema (if any) Application Code parse return DOM tree

July 15, 2008James Atlas - CISC37038 DOM Programming – Creating the DOM Tree How does the DOM API generate the tree representing the XML document? How does the DOM API generate the tree representing the XML document?  It uses a SAX parser!  The DOM APIs run a SAX parser to parse the XML document in an event-driven manner, constructing the DOM tree in memory

July 15, 2008James Atlas - CISC37039 DOM Programming – Basics To create a DOM DocumentBuilder with the JAXP packages To create a DOM DocumentBuilder with the JAXP packages DocumentBuilderFactory dbuilder_factory = DocumentBuilderFactory.newInstance(); dbuilder_factory.setValidating(true); DocumentBuilder dbuilder = dbuilder_factory.newDocumentBuilder(); Build a document tree from XML data found in a particular file Build a document tree from XML data found in a particular file FileReader file_in = new FileReader(“thefile.xml”); Document doc = dbuilder.parse(new InputSource(file_in));

July 15, 2008James Atlas - CISC37040 DOM Programming – Example 1import org.w3c.dom.*; 2import javax.xml.parsers.*; 3import org.xml.sax.*; 4 5public class DOMExample { 6 public static void main(String [] args) { 8 try { 9 System.out.println("Creating Document builder."); 10 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 11 dbf.setValidating(true); 12 DocumentBuilder db = dbf.newDocumentBuilder(); 13 System.out.println(“Ready to parse!”); 14 FileReader file_in = new FileReader(“theFile.xml”); 15 Document doc = db.parse(new InputSource(file_in)); 16 System.out.println("Parsed document, ready to process."); 17 myDOMTreeProcessor proc = new myDOMTreeProcessor(); 18 proc.process(doc, System.out); 19 } 20 catch (Exception e) { 21 System.err.println("XML Exception thrown: " + e); 22 e.printStackTrace(); 23 } 24 } 25} If want to validate

July 15, 2008James Atlas - CISC37041 DOM Programming – Example MyDOMTreeProcessor MyDOMTreeProcessor

July 15, 2008James Atlas - CISC37042 Changing the DOM Tree After you have the DOM tree, you can: After you have the DOM tree, you can:  search for particular nodes  extract element and text values  alter the tree: add elements to the tree or change them add elements to the tree or change them add attributes to elements or change their values add attributes to elements or change their values re-arrange elements and subtrees re-arrange elements and subtrees synthesize entirely new trees or subtrees synthesize entirely new trees or subtrees If you create a new tree or subtree, you should apply the normalize() method before processing it further If you create a new tree or subtree, you should apply the normalize() method before processing it further  optimizes layout

July 15, 2008James Atlas - CISC37043 XML Stylesheet Language (XSL) Core XML technology for performing transformations to and on XML documents Core XML technology for performing transformations to and on XML documents Offers extensive template matching and processing instructions for transforming XML data into other XML-like data Offers extensive template matching and processing instructions for transforming XML data into other XML-like data  e.g., XML->XML, XML->HTML, XML->text A programming language onto itself A programming language onto itself  Geared towards pattern matching and formatting

July 15, 2008James Atlas - CISC37044 XSL Transformations (XSLT) An XSL Processor is a system (usually invoked through an object interface) that can apply XSLT transforms to some XML input and generate another document (normally the data in another form) An XSL Processor is a system (usually invoked through an object interface) that can apply XSLT transforms to some XML input and generate another document (normally the data in another form) Transformation rules are expressed in XSL Transformation rules are expressed in XSL JAXP includes the Java implementation of the Apache Xalan XSLT processor JAXP includes the Java implementation of the Apache Xalan XSLT processor

July 15, 2008James Atlas - CISC37045 XSL Transformations (XSLT) XML Input file Output file (may or may not be XML) XSLT Declarations XSLT Processor A concrete example: A concrete example: 

July 15, 2008James Atlas - CISC37046 XML Programming - Transformations Advantage of the DOM programming model: can be used easily with XSL Advantage of the DOM programming model: can be used easily with XSL JAXP fully supports XSLT with the package javax.xml.transform and its sub-packages JAXP fully supports XSLT with the package javax.xml.transform and its sub-packages The sequence of steps for creating and applying transforms with XSLT and Xalan is The sequence of steps for creating and applying transforms with XSLT and Xalan is  Obtain or create a DOM tree, create a Source from it  Create a TransformerFactory  Create a Templates object based on a particular XSLT document  Create a Transformer object from the Templates object  Create an output Results object  Apply the Transformer to the Source and the Result

July 15, 2008James Atlas - CISC37047 Summary XML is a technology for storing data in a standard, portable, and text-based way   Eases communication between remote programs   Basis of SOAP: web service messages Java has packages to help your Java programs parse XML, build XML documents, and perform XML transformations Two basic models for XML parsing   SAX: sequential access, event-driven   DOM: in-memory tree structure XSLT can be used to transform XML into other XML or other textual formats

July 15, 2008James Atlas - CISC37048 XML Limitations Verbose descriptions Verbose descriptions  Can be redundant Hierarchical rather than relational model Hierarchical rather than relational model  Relational: databases  Must choose between … … … …