Integrating XML with J2EE - Summary (Page 14 of 14 )
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
What are the major characteristics of XML?
XML is a human readable, structured data-encoding format that is generic, simple, flexible, extensible and free to use.
What is the difference between well-formed and valid XML.
Well-formed XML is syntactically and structurally correct. XML is only valid if it complies with the constraints of a DTD or XML schema.
What are the J2EE APIs and specifications that support the processing of XML?
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
What are the main differences between SAX and DOM?
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.
- 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.
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.
© Copyright Pearson Education. All rights reserved.
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.
|
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |