1 / 11

Java API for XML Processing (JAXP)

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 ). XML Basics.

shika
Download Presentation

Java API for XML Processing (JAXP)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. XML Basics • 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. <nameattribute="value">content</name>

  3. XML Basics • XML requires that elements be properly nested • A comment is enclosed between "<!--" and "-->". • XML reserves certain characters. To express these characters in your document, use the following: &amp; & ampersand &lt; < less than &gt; > greater than &apos; ‘ apostrophe &quot; “ 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 tutorialhttp://java.sun.com/javaee/5/docs/tutorial/doc/bnbem.html#bnbewhttp://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?cc=&prod=xoap&par=1012383874&key=49ead562833bfce4 • Register with weather.com at http://www.weather.com/services/xmloap.html and get your own partner ID and license key.

More Related