Entering content frame

Background documentation ContentHandler and DefaultHandler Implementation Locate the document in its SAP Library structure

Example 1:

public class SAXTreeStructure extends DefaultHandler {

   public void startElement(String namespaceURI, String localName,

       String rawName, Attributes atts) {

     System.out.println("Start Element: " + rawName);

   }

   public void endElement(String namespaceURI, String localName,

       String rawName) {

     System.out.println("End Element  : " + rawName);

   }

   public void characters(char []data, int off, int length) {

     System.out.println("Characters   :    " + new String(data,

      off, length));

   }

}

 

Example 2:

public class JAXPSAXExample2 extends DefaultHandler {

  public void setDocumentLocator(Locator locator) {

    System.out.println("Method setDocumentLocator(" + locator +

      ")");

  }

  public void startDocument() throws SAXException {

    System.out.println("Method startDocument().");

  }

  public void endDocument() throws SAXException {

    System.out.println("Method endDocument().");

  }

  public void startPrefixMapping(String prefix, String uri) throws

       SAXException {

    System.out.println("Method startPrefixMapping(" + prefix + ",

      " + uri + ").");

  }

  public void endPrefixMapping(String prefix) throws SAXException{

    System.out.println("Method endPrefixMapping(" + prefix +

      ").");

  }

  public void startElement(String namespaceURI, String localName,

       String qName, Attributes atts) throws SAXException {

    System.out.println("Method startElement(" + namespaceURI + ",

       " + localName + ", " + qName + ", " + atts + ").");

  }

  public void endElement(String namespaceURI, String localName,

       String qName) throws SAXException {

    System.out.println("Method endElement(" + namespaceURI + ", "

      + localName + ", " + qName + ").");

  }

  public void characters(char[] ch, int start, int length) throws

      SAXException {

    System.out.println("Method characters(" + new String(ch,

      start, start + length) + ").");

  }

  public void ignorableWhitespace(char[] ch, int start, int

                                     length) throws SAXException {

    System.out.println("Method ignorableWhitespace(" + new

      String(ch, start, start + length) + ").");

  }

  public void processingInstruction(String target, String data)

       throws SAXException {

    System.out.println("Method processingInstruction(" + target +

       ", " + data + ").");

  }

  public void skippedEntity(String name) throws SAXException {

    System.out.println("Method skippedEntity(" + name + ").");

  }

  public InputSource resolveEntity(String publicId, String

                                   systemId) throws SAXException {

    System.out.println("Method resolveEntity(" + publicId + ", " +

      systemId + "). Resolving to: data\\" + systemId);

    return new InputSource("data/" + systemId);

  }

 

  public static void main(String[] args) throws Exception {

    String xml = "data/rich_ii.xml";

    SAXParserFactory factory = SAXParserFactory.newInstance();

    factory.setValidating(true);

    SAXParser parser = factory.newSAXParser();

    System.out.println(" validating:      " +

      parser.isValidating());

    System.out.println(" namespace-aware: " +

      parser.isNamespaceAware());

    System.out.println("");

    parser.parse(xml, new JAXPSAXExample2());  }

}

 

 

 

Leaving content frame