Generating XML

At the beginning of this chapter, you learned about using XML as a medium for doing data interchange. Suppose you want to send a vendor an XML file with order data in it. You could just write a method that creates the XML manually using prints, but this is dangerous because you might forget to include an end tag or you might make some other simple syntactic XML mistake. You can use DOM to generate a file on the fly from database data and be assured that it will be formatted as proper XML. Again, you need to start by defining a DTD for the XML file that's going to hold your orders (see Listing 14.7)

Listing 14.7. Order.dtd
 <?xml version='1.0' encoding='UTF-8' ?> <!ELEMENT File (Order)*> <!ELEMENT Order (email_address, address, ...

Get MySQL™ and JSP™ Web Applications: Data-Driven Programming Using Tomcat and MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.