
<price delivery=”5”>999.00</price>
<price delivery=”15”>899.00</price>
</vendor>
but it would ignore the contact information. In general, it’s a good idea to
simply ignore unknown elements. Doing so provides more flexibility when
the document evolves.
Enforce a Structure
It’s not difficult to enforce a specific structure. The following code snippet
checks the structure and throws a SAXException if a vendor element con-
tains anything but name or price elements.
case VENDOR:
if(name.equals(“name”))
{
state = VENDOR_NAME;
currentElement = new LeafElement(name,attributes);
}
else if(name.equals(“price”))
{
state = VENDOR_PRICE;
currentElement = new LeafElement(name,attributes); ...