Java 2EE and XML Development

Скачать в pdf «Java 2EE and XML Development»
Figure 3.2


Customer data represented using a DOM tree


Listing 3.2 shows what the customer DOM might look like if it were serialized out to a file. However, based on the requirements of your application, it is possible that this data could be transient and never be stored in a file.


Remember to keep the concepts of an XML data structure and an XML file separate in your mind.


Listing 3.2 Customer XML data serialized to a file


<?xml version=»1.0″?>


<!— Reference to a DTD to validate our customer data —> <iDOCTYPE customer SYSTEM «http://www.example.com/customer.dtd«>


<customer id=»123456″>


<first-name>John</first-name>


<last-name>Doe</last-name>


<address>


<street>123 Main</street>


<city>Anytown</city>


<state>CA</state>


<zip>99999</zip>


</address>


<phone>800-555-9999</phone>


<email-address>john@doe.com</email-address>


</customer>


It is clearly beneficial to use XML in our component interfaces from the standpoints of flexibility and reusability. Though our discussion used a simple example, the concepts can be applied to larger systems where the advantages of an XML approach become even more evident.

3.1.2 Implementing XML value objects


Now that we have chosen to use XML for our internal data representation, let’s walk through a more robust example using the value object approach. For purposes of this implementation, we’ll use the JDOM API. Later in this section, we will discuss the use of JDOM over DOM in this setting. As we discussed in chapter 2, JDOM is layered on top of the DOM and SAX APIs, as well as specific parser and XSLT engines, to provide a Java-friendly way to use XML structures. Here we use JDOM to create new XML data structures, manipulate them, and share them with clients.

Скачать в pdf «Java 2EE and XML Development»