Class XMLSerializer

  • All Implemented Interfaces:
    javax.xml.bind.ValidationEventHandler, ErrorHandler

    public final class XMLSerializer
    extends Coordinator
    Receives XML serialization event and writes to XmlOutput.

    This object coordinates the overall marshalling efforts across different content-tree objects and different target formats.

    The following CFG gives the proper sequence of method invocation.

     MARSHALLING  :=  ELEMENT
     ELEMENT      :=  "startElement" NSDECL* "endNamespaceDecls"
                            ATTRIBUTE* "endAttributes" BODY "endElement"
     
     NSDECL       :=  "declareNamespace"
     
     ATTRIBUTE    :=  "attribute"
     ATTVALUES    :=  "text"*
     
     
     BODY         :=  ( "text" | ELEMENT )*
     

    A marshalling of one element consists of two stages. The first stage is for marshalling attributes and collecting namespace declarations. The second stage is for marshalling characters/child elements of that element.

    Observe that multiple invocation of "text" is allowed.

    Also observe that the namespace declarations are allowed only between "startElement" and "endAttributes".

    Exceptions in marshaller

    IOException, SAXException, and XMLStreamException are thrown from XmlOutput. They are always considered fatal, and therefore caught only by MarshallerImpl.

    AccessorException can be thrown when an access to a property/field fails, and this is considered as a recoverable error, so it's caught everywhere.

    Author:
    Kohsuke Kawaguchi