Home arrow Java & J2EE arrow Page 14 - Integrating XML with J2EE

Summary - Java

In this article, Martin Bond discusses XML and its associated APIs and standards, and how XML can be used to create flexible structured data that is inherently portable. This excerpt is from chapter (Day) 16 of Teach Yourself J2EE in 21 Days, second edition, by Martin Bond, et. al. (Sams, ISBN: 0672325586)

TABLE OF CONTENTS:
  1. Integrating XML with J2EE
  2. Benefits and Characteristics of XML
  3. Structure and Syntax of XML
  4. Structure of an XML Document
  5. Well-formed XML Documents
  6. Namespaces
  7. Element Type Declarations
  8. XML Schemas
  9. Parsing XML
  10. Parsing XML Using SAX
  11. Document Object Model (DOM) Parser
  12. Modifying a DOM Tree
  13. Java Architecture for XML Binding
  14. Summary
By: Sams Publishing
Rating: starstarstarstarstar / 23
November 16, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Today, you have had a very quick, and necessarily brief, introduction to XML and the APIs and technologies available in J2EE to parse and generate XML data. You have seen how XML can be used to create flexible structured data that is inherently portable. With DTDs and XML Schemas, you were shown how this data can also be validated. You have been introduced to several different ways of parsing an XML document with SAX, DOM, JAXP, or JAXB, and you should now recognize the advantages and disadvantages of each technique.

Tomorrow, you will extend your XML knowledge to include XML transformations.

Q&A

  1. What are the major characteristics of XML?

  2. XML is a human readable, structured data-encoding format that is generic, simple, flexible, extensible and free to use.

  1. What is the difference between well-formed and valid XML.

  2. Well-formed XML is syntactically and structurally correct. XML is only valid if it complies with the constraints of a DTD or XML schema.

  1. What are the J2EE APIs and specifications that support the processing of XML?

  2. The J2EE APIs and specifications that supports XML processing are JAXP (Java API for XML Processing), SAX (Simple API for XML Parsing), DOM (Document Object Model), and XLST for transforming XML documents

  1. What are the main differences between SAX and DOM?

  2. SAX provides a serial event-driven parser. DOM is more flexible in that it builds an in-memory representation of the document that can be manipulated randomly (that is, nodes can be addressed or processed in any order). SAX is generally more efficient (faster), while DOM can be a heavy user of memory.

Exercise

To practice working with XML, try the following two exercises; the first is relatively simple, but the second requires a little more effort.

  1. Extend the WebDDBuilder application to optionally read in an existing web.xml file and add the new <servlet> and <servlet-mapping> elements from the servlet class and URL pattern information provided on the command line.

Hint: Most of the code is already in place. You will need to create another constructor to build the DOM tree from an existing DD whose filename is supplied as the last (optional) parameter on the command line. A simple web.xml file is provided in the Day16/solution/XML directory.


Tip - If your web.xml file has a non-local DTD specified in the DOCTYPE element (this will be the case if you are using a J2EE 1.3 or earlier web.xml file), you will require access to the Web for the parser to validate the XML.


  1. Enhance your solution to check for duplicate servlet names. The servlet name in a Web Application DD must be unique. Ensure that the program will not add the same servlet class twice by checking for duplicate servlet names before adding the new entry.

A solution is provided in the Day 16 solution directory.

This chapter is from Teach Yourself J2EE in 21 Days, second edition, by Martin Bond et. al. (Sams, 2004, ISBN: 0-672-32558-6). Check it out at your favorite bookstore today. Buy this book now.



 
 
>>> More Java & J2EE Articles          >>> More By Sams Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: