DOC PREVIEW
CMU ISM 95702 - Java and XML (DOM and SAX)

This preview shows page 1-2-3-4-5-6-7-8-53-54-55-56-57-58-59-108-109-110-111-112-113-114-115 out of 115 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 115 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Java and XML (DOM and SAX)Slide 2FixedFloatSwap.xmlFixedFloatSwap.dtdSlide 5Tree BenefitsSlide 7Slide 8Event-Driven BenefitsSome of the XML API’s in JDK1.4There are more in JWSDPImportant SAX interfaces and classes (JDK1.4)Processing XML with SAXSlide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21ProcessingSlide 23Slide 24Slide 25Slide 26Slide 27Accessing the swap from the internetThe Deployment DescriptorSlide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 39Slide 40Let’s Add Back the DTD…And reference the DTD in the XMLWe get new outputWe don’t have to go through a servlet…Tomcat can send the filesThe InputSource ClassSlide 46But what about the DTD?EntityResolverSlide 49XML DOMSlide 51Slide 52Agreement.xmlSlide 54Slide 55Some DOM Documentation from JavaSoftThe Node InterfacePropertiesSome Methods of NodeSlide 60Slide 61Slide 62Slide 63Slide 64The NodeList InterfaceThere are only two methods of the NodeList InterfaceSlide 67The Element InterfaceSlide 69Slide 70Slide 71The CharacterData InterfaceSlide 73The Document InterfaceSlide 75Slide 76Slide 77Slide 78An ExampleSlide 80Slide 81Slide 82Slide 83OutputRead-Process-Write XMLChangeGrade.javaSlide 87Slide 88Slide 89Slide 90Slide 91Using the InputSource classUsing the InputSource ClassSlide 94Slide 95Slide 96Example - A TreePrint ClassSlide 98Slide 99Slide 100Slide 101Slide 102GOALSlide 104Slide 105Slide 106Slide 107Slide 108A SAX Example Using a FactorySlide 110Slide 111Slide 112Slide 113Slide 114Slide 115OCT 1Java and XML (DOM and SAX) Some of the material for these slides came from the followingsources: “XML a Manager’s Guide” by Kevin Dick “The XML Companion” by Bradley Java Documentation from Sun Microsystems “XML and Java” by Maruyama, Tamura and Uramoto On and Off the internet…OCT 2Java and XML (DOM and SAX) • Parser Operations with DOM and SAX overview • Processing XML with SAX (locally and on the internet)• Processing XML with DOM (locally and on the internet)OCT 3FixedFloatSwap.xml <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE FixedFloatSwap SYSTEM "FixedFloatSwap.dtd"><FixedFloatSwap> <Notional>100</Notional> <Fixed_Rate>5</Fixed_Rate> <NumYears>3</NumYears> <NumPayments>6</NumPayments></FixedFloatSwap>OCT 4FixedFloatSwap.dtd <?xml version="1.0" encoding="utf-8"?><!ELEMENT FixedFloatSwap (Notional, Fixed_Rate, NumYears, NumPayments ) ><!ELEMENT Notional (#PCDATA) ><!ELEMENT Fixed_Rate (#PCDATA) ><!ELEMENT NumYears (#PCDATA) ><!ELEMENT NumPayments (#PCDATA) >OCT 5Operation of a Tree-based ParserTree-BasedParserApplicationLogicDocument TreeValidXML DTDXML DocumentOCT 6Tree Benefits•Some data preparation tasks require early access to data that is further along in the document (e.g. we wish to extract titles to build a table of contents)•New tree construction is easier (e.g. XSLT works from a tree to convert FpML to WML)OCT 7Operation of an Event Based ParserEvent-BasedParserApplicationLogicValidXML DTDXML DocumentOCT 8Operation of an Event Based ParserEvent-BasedParserApplicationLogicValidXML DTDXML Documentpublic void startDocument ()public void endDocument ()public void startElement (…))public void endElement (…)public void characters (…))public void error(SAXParseException e) throws SAXException { System.out.println("\n\n--Invalid document ---" + e); }OCT 9Event-Driven Benefits•We do not need the memory required for trees•Parsing can be done faster with no tree construction going onOCT 10Some of the XML API’s in JDK1.4OCT 11There are more in JWSDPOCT 12Important SAX interfaces and classes (JDK1.4) class InputSource -- A single input source for an XML entity interface XMLReader -- defines parser behavior (implemented by Xerces’ SAXParser and others) Four core SAX2 handler interfaces:•EntityResolver •DTDHa n dler •ContentHan dler •ErrorHandler Implemented byclass DefaultHandlerOCT 13Processing XML with SAX interface XMLReader -- defines parser behavior (implemented by Xerces’ SAXParser) XMLReader is the interface that an XML parser's SAX2 driver must implement. This interface allows an application to set and query features and properties in the parser, to register event handlers for document processing, and to initiate a document parse.OCT 14Processing XML with SAX• We will look at the following interfaces and classes and then study an example interface ContentHandler -- reports on document events interface ErrorHandler – reports on validity errors class DefaultHandler – implements both of the above plus two othersOCT 15public interface ContentHandlerReceive notification of general document events. This is the main interface that most SAX applications implement: if the application needs to be informed of basic parsing events, it implements this interface andregisters an instance with the SAX parser using the setContentHandler method.The parser uses the instance to report basic document-related events like thestart and end of elements and character data.OCT 16void characters(…) Receive notification of character data.void endDocument(…) Receive notification of the end of a document.void endElement(…) Receive notification of the end of an element.void startDocument(…) Receive notification of the beginning of a document. void startElement(…) Receive notification of the beginning of an element.Some methods from the ContentHandler InterfaceOCT 17public interface ErrorHandlerBasic interface for SAX error handlers. If a SAX application needs to implement customized error handling, it must implement this interface and then register an instance with the SAX parser.The parser will then report all errors and warnings through this interface.For XML processing errors, a SAX driver must use this interface instead ofthrowing an exception: it is up to the application to decide whether to throwan exception for different types of errors and warnings. Note, however,that there is no requirement that the parser continue to provide useful informationafter a call to fatalError.OCT 18public interface ErrorHandlerSome methods are:void error(SAXParseException exception) Receive notification of a recoverable error.void fatalError(SAXParseException exception) Receive notification of a non-recoverable error.void warning(SAXParseException


View Full Document

CMU ISM 95702 - Java and XML (DOM and SAX)

Documents in this Course
Homework

Homework

12 pages

Lecture

Lecture

25 pages

Lecture

Lecture

21 pages

Lecture

Lecture

24 pages

Exam

Exam

11 pages

Homework

Homework

16 pages

Homework

Homework

38 pages

lecture

lecture

38 pages

review

review

7 pages

lecture

lecture

18 pages

review

review

8 pages

Chapter2

Chapter2

32 pages

Lecture 4

Lecture 4

47 pages

Lecture

Lecture

22 pages

Naming

Naming

26 pages

lecture

lecture

34 pages

lecture

lecture

42 pages

lecture

lecture

112 pages

Lecture

Lecture

33 pages

Axis

Axis

43 pages

lecture

lecture

32 pages

review

review

17 pages

Lecture

Lecture

53 pages

Lecture

Lecture

80 pages

Lab

Lab

14 pages

Load more
Download Java and XML (DOM and SAX)
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java and XML (DOM and SAX) and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java and XML (DOM and SAX) 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?