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

This preview shows page 1-2-3-4-5-6-7-51-52-53-54-55-56-57-58-102-103-104-105-106-107-108 out of 108 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 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 108 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 108 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Java and XML (DOM and SAX)Slide 2FixedFloatSwap.xmlFixedFloatSwap.dtdPowerPoint PresentationTree 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 108Internet Technologies 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…Internet Technologies 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)Internet Technologies 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>Internet Technologies 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) >Internet Technologies 5Operation of a Tree-based ParserTree-BasedParserApplicationLogicDocument TreeValidXML DTDXML DocumentInternet Technologies 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)Internet Technologies 7Operation of an Event Based ParserEvent-BasedParserApplicationLogicValidXML DTDXML DocumentInternet Technologies 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); }Internet Technologies 9Event-Driven Benefits•We do not need the memory required for trees•Parsing can be done faster with no tree construction going onInternet Technologies 10Some of the XML API’s in JDK1.4Internet Technologies 11There are more in JWSDPInternet Technologies 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:•EntityRe solver •DTDHa n dler •ContentHan dler •ErrorHandler Implemented byclass DefaultHandlerInternet Technologies 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.Internet Technologies 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 othersInternet Technologies 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.Internet Technologies 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 InterfaceInternet Technologies 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.Internet Technologies


View Full Document

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

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?