Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Java Session 9 New York University School of Continuing and Professional Studies.

Similar presentations


Presentation on theme: "Advanced Java Session 9 New York University School of Continuing and Professional Studies."— Presentation transcript:

1

2 Advanced Java Session 9 New York University School of Continuing and Professional Studies

3 2 Objectives Java and XML –Introduction to XML –Parsing XML –Web publishing frameworks using XML/XSLT

4 3 Java and XML Java – Portable Code XML – Portable Data XML for Presentation XML for Communication/Integration db DB Server server1 server 2 XML data

5 4 What is XML Meta language – that is used to define other languages Markup language that specifies neither the tag set, nor the grammar

6 5 XML The Wood Shop $1999.99 2 excellent

7 6 XML blue 3 average

8 7 Related Acronyms PI – Processing Instruction –Provide information to the application – parsers just pass them on to the application –<?xml: --- is for the parser DTD – Document Type Definition –Establishes a set of constraints –Defines valid elements – and valid attributes Namespaces – scope –Provides a way to distinguish tags by the same name

9 8 Related Acronyms XSL and XSLT – Extensible Stylesheet Language, Transformation –Provides a mechanism to convert an XML document to other formats such as HTML, PDF, WML etc. XPath – XML Path Language –A specification to locate a specific item within an XML document – used heavily in XSL

10 9 Related Acronyms XML Schema –Upcoming replacement for DTD XQL –Query language with functionality of SQL XSP –Similar to Java Server pages except that the xsps are “xml” documents with embedded java code.

11 10 Constraining XML Document Type Definition – DTD Specify elements Specify element hierarchy (nesting) Specify textual data - #PCDATA Keyword ANY says anything Keyword EMPTY says “empty” Entity references with <!ENTITY &amp ? -- oncr or not at all + -- 1 to n times * -- 0 to n times

12 11 Attributes <!ATTLIST [Enclosing Element] [Attr name] [type] [modifiers] Attribute Types – CDATA “name=“ in HTML enumeration “align=“ in HTML #IMPLIED #REQUIRED #FIXED

13 12 Parsing XML Two models for parsing XML –DOM – Document Object Model – creates a tree view of the XML document. Entire document is loaded. –SAX – Simple API for XML – much more popular.

14 13 Document Object Model A set of interfaces and classes –Building the document tree DOMParser parser = new DOMParser(); parser.parse(uri); Document doc = parser.getDocument(); –Traverse the tree recursively based on node type – DOCUMENT_NODE ELEMENT_NODE TEXT_NODE, CDATA_SECTION_NODE PROCESSING_INSTRUCTION_NODE ENTITY_REFERENCE_NODE DOCUMENT_TYPE_NODE

15 14 SAX Event based API for parsing XML documents Set of interfaces and classes – –ContentHandler –ErrorHandler

16 15 SAX ContentHandler startDocument() endDocument() processingInstruction() startPrefixMapping() endPrefixMapping() startElement() endElement() characters() ignorableWhitespace()

17 16 SAX ErrorHandler warning() error() fatalError()

18 17 SAX Parsing Example XMLReader parser = (XMLReader) Class.forName(parserName).newInstance(); parser.setContentHandler(counter); parser.setErrorHandler(counter); parser.parse(uri);

19 18 XSL template XSL is XML Locate a particular element or set of elements within the input XML document and apply a rule or set of rules <!---- rules for formatting the book -- 

20 19 XSL control structures

21 20 XSL elements 5 hello

22 21 XSL Transformation XML document XSL stylesheet Transformation XML document

23 22 XSL Transformer TransformerFactory Transformer StreamSource StreamResult

24 23 Simple Transformation TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer ( new StreamSource("birds.xsl")); transformer.transform( new StreamSource("birds.xml"), new StreamResult( new FileOutputStream("birds.out")));

25 24 Thank you


Download ppt "Advanced Java Session 9 New York University School of Continuing and Professional Studies."

Similar presentations


Ads by Google