Unformatted text preview:

Java XMLOutlineXMLExample HTMLExampleXML is notXML isDifferences from HTMLExamplesVocabularyDocument TypesDTDReading a DTDElementAttribute ListsSlide 16Slide 17ConformityDTD LimitationsProgramming with XMLDOMDOM RepresentationSlide 23Working with the DOMSlide 25Better with ValidationSlide 27Problems with DOMSAXSAX EventsSlide 31How to writeSlide 33XML OutputSlide 35Java XMLIS 3136.3.2003OutlineXML documentsXML in JavaDOMSAXXML OutputXMLHTML-like markupSemantic meaningExample HTML<html><h3>Message</h3><b>To:</b> [email protected]<br><b>From:</b> [email protected]<br><b>Subject:</b>XML Is Really Cool<p><hr>How many ways is XML cool? Let me count the ways...<p></html>Example<message> <to>[email protected]</to> <from>[email protected]</from><subject>XML Is Really Cool</subject> <text> How many ways is XML cool? Let me count the ways... </text></message>XML is nota languageIt is a standard for creating task-specific formal languagesIn the pastevery application has its own representationdifficult for applications to interoperateXML ishuman readablenot platform-specificnot presentationalfixed syntaxvalidity separate from interpretationDifferences from HTMLcase-sensitiveend tags not optionalempty tags have special syntaxattribute values must be in quotesXHTMLExamplesmembersflightsVocabularyHeader<?xml version=“1.0”?>ElementsmembermembersAttributeslevel=“standard”Entities&amp;Document TypesA document type is specification for a family of documentsemail messagesmember account data filesDefining a document typedeciding what can be saidhow it can be saidattaching meaningful labelsDTDDocument Type Definitionone of many proposals for defining XML languagesothersXML Schema, Schematron, DSD, RelaxDTDsbased on the original SGML DTDsnot written in XMLlimited in certain respectsEasiest to learnReading a DTD<!ELEMENTdefines an element<!ATTLISTassociates elements and attributes<!ENTITYdefines entitiesElementElement namecontent modeltext or other dataelementssequenceschoicesAttribute ListsName of elementFor each attributenamecontent typevaluespresencedefaultExamplesElement<!ELEMENT members (member*)><!ELEMENT member (name, enroll-date, last-flight-date?, miles, benefit-level)>Attlist<!ATTLIST member id CDATA #REQUIRED><!ATTLIST benefit-levellevel (standard | silver | gold | platinum) "standard">Examplesflights.dtdmembers.dtdConformityIf I just have an XML documentI have some dataIf I have XML document and DTDI have some idea what the document is supposed to representIf I have XML document validated by DTDI know that the document is organized as the DTD saysDTD LimitationsNo way to specify types of thingsid must be a numberorigin must be a three-character stringDefault values only for attributesMust have a separate DTD parsernot XMLNo import or includeNo inheritanceOO element declarationProgramming with XMLBasic problemuse an XML document in a Java programTwo waysBuild an internal representation of the whole thingExtract just the parts you wantDOMDocument Object ModelModelof the XML documentcomposed of objectsThink of the document as a treeDOM RepresentationDOM RepresentationNodestext nodeselement nodeswhitespace nodesList of childrenordered top to bottomWorking with the DOMNavigate from node to nodefrom Node to ChildListfrom ChildList to NodeEasier with XPath/member[0]/name/lastExampleDOMExtractExtractlast namemilesbenefit levelBetter with ValidationIf we validate the documentwe know that the document obeys the structuresimpler destructuringExampleDOMExtract2Problems with DOMMay not want the whole documentToo bigOnly interested in certain partsMemory intensiveSlowSAXSimple API for XMLWatch the parser parseParsing = a stream of eventseach event calls a methodlike GUI event handlingSAX EventsstartDocumentendDocumentstartElementendElementcharacterserrorsExamplemembers.xmlHow to writestate machinebeginnings and ends of elements change statein each stateprocess relevant informationExampleSAXExtractXML OutputRather awkwardUse XML transformationsbut don’t do any transformingprovides an output streamExampleDOMOutputReads in the fileThen adds 1000 to each miles entryOutputs the


View Full Document

DePaul IS 313 - Java XML

Download Java XML
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 XML 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 XML 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?