Graphic Java
Create XML files using JSP
David Geary
Listing 4.

package com.companyName.beans.model;


public class Item implements {
	private String name, description;
	private float price;

	public Item() { }

	public Item(String name, String description, float price) {
	// setters and getters for name, description, and
	// price omitted

	public void printXml(PrintStream s, int indent) {
		doIndent(s,indent); 	s.println("<item>");

		doIndent(s,indent, 2); 	s.println("<name>");
		doIndent(s,indent, 3); 	s.println(getName());
		doIndent(s,indent, 2); 	s.println("</name>");

		doIndent(s,indent, 2); 	s.println("<description>");
		doIndent(s,indent, 3); 	s.println(getDescription());
		doIndent(s,indent, 2); 	s.println("</description>");

		doIndent(s,indent, 2); 	s.println("<price>");
		doIndent(s,indent, 3); 	s.println(getPrice());
		doIndent(s,indent, 2); 	s.println("</price>");

		doIndent(s,indent); 	s.println("</item>");
	private void doIndent(PrintStream s, int indent, int cnt) {
		for(int i=0; i < cnt; ++i) {
	private void doIndent(PrintStream s, int indent) {
		for(int i=0; i < indent; ++i) {
			s.print("   ");

About the Author

David Geary was the lead engineer for the Java Management API GUI toolkit, and is now an independent Java consultant. David is the author of Graphic Java—Mastering the JFC. He can be contacted at [email protected].