Example 1: Extracting phone numbers from a directory.

This example shows how to write a SAX filter to extract phone numbers from a directory file written in XML.
MAIN
  DEFINE f om.SaxDocumentHandler
  LET f = om.SaxDocumentHandler.createForName("module1")
  CALL f.readXmlFile("customers")
END MAIN
Note:
  1. The parameter of the createForName() method specifies the name of a source file that has been compiled into a .42m file ("module1.42m" in our example).
The module "module1.4gl":
FUNCTION startDocument()
END FUNCTION

FUNCTION processingInstruction(name,data)
  DEFINE name,data STRING
END FUNCTION

FUNCTION startElement(name,attr)
  DEFINE name STRING
  DEFINE attr om.SaxAttributes 
  DEFINE i INTEGER
  IF name="Customer" THEN
     DISPLAY attr.getValue("lname")," ",
            attr.getValue("fname"),":",
            COLUMN 60, attr.getValue("phone")
  END IF
END FUNCTION

FUNCTION endElement(name)
  DEFINE name STRING
END FUNCTION

FUNCTION endDocument()
END FUNCTION

FUNCTION characters(chars)
  DEFINE chars STRING
END FUNCTION

FUNCTION skippedEntity(chars)
  DEFINE chars STRING
END FUNCTION
The XML file "customers":
<Customers>
  <Customer customer_num="101" fname="Ludwig" lname="Pauli"
    company="All Sports Supplies" address1="213 Erstwild Court"
    address2="" city="Sunnyvale" state="CA" zip-code="94086"
    phone="408-789-8075" />
  <Customer customer_num="102" fname="Carole" lname="Sadler"
    company="Sports Spot" address1="785 Geary St"
    address2="" city="San Francisco" state="CA" zip-code="94117"
    phone="415-822-1289" />
  <Customer customer_num="103" fname="Philip" lname="Currie"
    company="Phil&apos;s Sports" address1="654 Poplar"
    address2="P. O. Box 3498" city="Palo Alto" state="CA"
    zip-code="94303" phone="415-328-4543" />
</Customers>