Class XmlLineNumberParser

java.lang.Object
org.apache.camel.parser.helper.XmlLineNumberParser

public final class XmlLineNumberParser extends Object
An XML parser that uses SAX to include line and column number for each XML element in the parsed Document.

The line number and column number can be obtained from a Node/Element using

 String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
 String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
 String columnNumber = (String) node.getUserData(XmlLineNumberParser.COLUMN_NUMBER);
 String columnNumberEnd = (String) node.getUserData(XmlLineNumberParser.COLUMN_NUMBER_END);
 
Mind that start and end numbers are the same for single-level XML tags.
  • Field Details

  • Method Details

    • parseXml

      public static Document parseXml(InputStream is)
      Parses the XML.
      Parameters:
      is - the XML content as an input stream
      Returns:
      the DOM model
      Throws:
      Exception - is thrown if error parsing
    • parseXml

      public static Document parseXml(InputStream is, String rootNames, String forceNamespace)
      Parses the XML.
      Parameters:
      is - the XML content as an input stream
      rootNames - one or more root names that is used as baseline for beginning the parsing, for example camelContext to start parsing when Camel is discovered. Multiple names can be defined separated by comma
      forceNamespace - an optional namespace to force assign to each node. This may be needed for JAXB unmarshalling from XML -> POJO.
      Returns:
      the DOM model
      Throws:
      org.apache.camel.RuntimeCamelException - is thrown if error parsing (wraps the underlying exception)