Class XmlDomUtil

java.lang.Object
dev.metaschema.databind.io.xml.XmlDomUtil

public final class XmlDomUtil extends Object
Utility methods for converting between StAX events and W3C DOM elements.

These methods support the any content feature by converting unmodeled XML content between the StAX event stream used during parsing and the DOM representation stored in XmlAnyContent.

  • Method Details

    • staxToElement

      @NonNull public static Element staxToElement(@NonNull org.codehaus.stax2.XMLEventReader2 reader) throws XMLStreamException
      Read an XML element from a StAX event reader and return it as a DOM Element.

      The reader must be positioned so that the next event is a XMLStreamConstants.START_ELEMENT. After this method returns, the reader will be positioned just past the matching XMLStreamConstants.END_ELEMENT.

      Parameters:
      reader - the StAX event reader, positioned before a start element
      Returns:
      the DOM element containing the full subtree
      Throws:
      XMLStreamException - if an error occurs while reading XML events
    • elementToStax

      public static void elementToStax(@NonNull Element element, @NonNull org.codehaus.stax2.XMLStreamWriter2 writer) throws XMLStreamException
      Write a DOM Element to a StAX stream writer.

      This writes the complete element subtree including attributes, namespace declarations, child elements, and text content.

      Parameters:
      element - the DOM element to write
      writer - the StAX stream writer to write to
      Throws:
      XMLStreamException - if an error occurs while writing to the stream