View RSS Feed

SAX.

Simple API for XML

  1. Java SAX Schema Validation

    by , 04-27-2012 at 06:16 PM
    It is possible to turn on XML Schema validation during parsing with a SAXParser. Here is how it looks:
    Java Code:
    Schema schema = null;
    try {
      String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
      SchemaFactory factory = SchemaFactory.newInstance(language);
      schema = factory.newSchema(new File(name));
    } catch (Exception e) {
        e.printStackStrace();
    }
    
    
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setSchema(schema);
    ...
    Tags: sax schema Add / Edit Tags
    Categories
    SAX.
  2. Java SAX DefaultHandler Exceptions

    by , 04-27-2012 at 06:16 PM
    The DefaultHandler class has three methods you can override to handle exceptions encountered during the XML parsing. Here they are:
    Java Code:
    public void warning(SAXParseException e) throws SAXException {
    }
    
    public void error(SAXParseException e) throws SAXException {
    }
    
    public void fatalError(SAXParseException e) throws SAXException {
    }
    Let's say that the parser encounters an illegal XML entity (like &notLegal;). The SAXParser ...
    Categories
    SAX.
  3. Java SAX Parser

    by , 04-27-2012 at 06:15 PM
    SAX is an abbreviation and means "Simple API for XML". A Java SAX XML parser is a stream oriented XML parser. It works by iterating over the XML and call certain methods on a "listener" object when it meets certain structural elements of the XML. For instance, it will call the listener object for the following "events":
    - startDocument
    - startElement
    - characters
    - comments
    - processing instructions
    - endElement
    - endDocument ...
    Categories
    SAX.
  4. SAX for Survival

    by , 04-27-2012 at 06:14 PM
    Compared to the DOM API, the SAX API is an attractive approach. SAX doesn't have a generic object model, so it doesn't have the memory or performance problems associated with abusing thenew operator. And with SAX, there is no generic object model to ignore if you plan to use a specific problem-domain object model instead. Moreover, since SAX processes the XML document in a single pass, it requires much less processing time.
    SAX does have a few drawbacks, but they are mostly related to the ...
    Categories
    SAX.
  5. SAX and DOM APIs

    by , 04-27-2012 at 06:14 PM
    The SAX API is event-based. XML parsers that implement the SAX API generate events that correspond to different features found in the parsed XML document. By responding to this stream of SAX events in Java code, you can write programs driven by XML-based data.

    The DOM API is an object-model-based API. XML parsers that implement DOM create a generic object model in memory that represents the contents of the XML document. Once the XML parser has completed parsing, the memory contains ...
    Tags: sax Add / Edit Tags
    Categories
    SAX.
  6. The Benefits of JAXP

    by , 11-29-2011 at 02:58 AM
    One of the most important technologies available in java is the APIs used to work with XML. There are basically two ways to work with XML documents. SAX involves an event driven means of processing XML using callbacks to handle the relevant events. DOM involves using an in-house tree structure of the XML document. Sun Microsystems created a Java API for XML Processing (JAXP) toolkit which makes XML manageable for all developers to use. It is a key component for exploiting all the possibilities with ...

    Updated 11-30-2011 at 03:01 PM by Java XML

    Categories
    JAXP , DOM , SAX.