Interface XMLMapper


  • public interface XMLMapper
    An XML mapper. Allows the creation of extensible streaming XML parsers.
    Author:
    David M. Lloyd
    • Method Detail

      • registerRootElement

        <T> void registerRootElement​(QName name,
                                     Supplier<XMLElementReader<T>> supplier)
        Add a known root element which can be read by XMLExtendedStreamReader.handleAny(Object).
        Parameters:
        name - the element name
        supplier - provider for the reader which handles the element It is recommended that supplier always creates new instance of the XMLElementReader instead of caching and returning always same instance. This way unused parsers can get GC-ed when not needed.
      • registerRootElement

        default <T,​N extends Namespace> void registerRootElement​(String localName,
                                                                       Set<N> namespaces,
                                                                       Function<N,​XMLElementReader<T>> readerFactory)
        Convenience method that registers a root element associated with a known set of namespaces, whose reader can be created from the specified factory.
        Type Parameters:
        T - the operating type of the reader
        N - the namespace type
        Parameters:
        localName - the local name of the known root element
        namespaces - a set of known namespaces for the specified the root element
        factory - a factory for creating an element reader for the specified the root element
      • parseDocument

        void parseDocument​(Object rootObject,
                           XMLStreamReader reader)
                    throws XMLStreamException
        Parse a document. The document must have a known, registered root element which can accept the given root object.
        Parameters:
        rootObject - the root object to send in
        reader - the reader from which the document should be read
        Throws:
        XMLStreamException - if an error occurs
      • deparseDocument

        void deparseDocument​(XMLElementWriter<?> writer,
                             Object rootObject,
                             XMLStreamWriter streamWriter)
                      throws XMLStreamException
        Format the element writer's output on to an XML stream writer.
        Parameters:
        writer - the element writer
        rootObject - the root object to send in
        streamWriter - the stream writer
        Throws:
        XMLStreamException - if an exception occurs