Class XmlStreamDetector

java.lang.Object
org.apache.camel.xml.io.util.XmlStreamDetector

public class XmlStreamDetector extends Object

A utility class to determine as quickly as possible (without reading entire stream) important information about an XML document. Most importantly we can collect:

  • name and namespace of root element
  • root element attributes and values
  • prefix:namespace mapping declared at root element
  • modeline declarations before root element

While we can have any kind of XML document and the namespaced content may be available at various places in the document, most sane documents can be examined simply by looking at the root element. This can help e.g., with jbang run camel@camel run to quickly detect what kind of XML document we're trying to run. This can speed later, full parsing, because we know upfront what's in the doc.

  • Constructor Details

    • XmlStreamDetector

      public XmlStreamDetector(InputStream xmlStream) throws IOException
      Creates a detector for XML stream. The stream should be managed (like try-resources) externally.
      Parameters:
      xmlStream - XML to collect information from
      Throws:
      IOException - thrown if there is a problem reading the file.
  • Method Details