greater than ' ‘ apostrophe " “ quotation mark"> greater than ' ‘ apostrophe " “ quotation mark">
Download presentation
Presentation is loading. Please wait.
1
Java API for XML Processing (JAXP) CSE 4/586: Distributed Systems Department of Computer Science and Engineering University at Buffalo, New York Jia Zhao (jiazhao@buffalo.edu)
2
eXtensible Markup Language (XML) – Its primary purpose is to facilitate the sharing of structured data across different information systems, particularly via the Internet. XML is a generic framework for storing any amount of text or any data whose structure can be represented as a tree: Root element:the document has exactly one root element Elements: The text enclosed by the root tags may contain an arbitrary number of XML elements E.g. content XML Basics
3
XML requires that elements be properly nested A comment is enclosed between " ". XML reserves certain characters. To express these characters in your document, use the following: & & ampersand < < less than > > greater than ' ‘ apostrophe " “ quotation mark
4
Schema Definition The schema of XML files is usually defined using Languages such as: Document Type Definition (.dtd): The oldest schema format for XML W3C XML Schema Language (.xsd): the successor of DTDs.
5
JAXP Allows to parse your data as a stream of events(SAX) or to build an object representation(DOM) of it. Simple API for XML (SAX) : event-driven serial-access mechanism that does element-by-element processing. The application registers to receive events as entities are encountered within the source document Document Object Model (DOM) : interface-oriented mechanism that allows for navigation of the entire document as if it were a tree of "Node" objects. The entire document is read into memory as a tree structure for random access by the calling application
6
SAX Parsing
7
DOM Parsing
8
JAXP- StAX Streaming API for XML (StAX) :a median between SAX and DOM for Java. The application moves the cursor forward - 'pulling' the information from the parser as it needs The XMLStreamReader interface in the StAX cursor API lets you read XML streams or documents in a forward direction only, one item in the infoset at a time.
9
JAXP- StAX The following methods are available for pulling data from the stream or skipping unwanted events: Get the value of an attribute Read XML content Determine whether an element has content or is empty Get indexed access to a collection of attributes Get indexed access to a collection of namespaces Get the name of the current event (if applicable) Get the content of the current event (if applicable)
10
Weather.com XML feed & WeatherParser The StAX tutorial which is part of the J2EE tutorial http://java.sun.com/javaee/5/docs/tutorial/doc/bnb em.html#bnbew http://www.ibm.com/developerworks/xml/library/ x-tipstx/ http://java.sun.com/javaee/5/docs/tutorial/doc/bnb em.html#bnbew http://www.ibm.com/developerworks/xml/library/ x-tipstx/ The weather.com SDK http://download.weather.com/web/xml/sdk.zip The weather.com DTD http://www.weather.com/documentation/xml/weather.dtd
11
Weather.com XML feed & WeatherParser Sample XML Feed http://xoap.weather.com/weather/local/14214?c c=&prod=xoap&par=1012383874&key=49ead 562833bfce4 http://xoap.weather.com/weather/local/14214?c c=&prod=xoap&par=1012383874&key=49ead 562833bfce4 Register with weather.com at http://www.weather.com/services/xmloap.html and get your own partner ID and license key.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.