Class 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);
     
    • Method Detail

      • parseXml

        public static Document parseXml​(InputStream is)
                                 throws Exception
        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,
                                        XmlLineNumberParser.XmlTextTransformer xmlTransformer,
                                        String rootNames,
                                        String forceNamespace)
                                 throws Exception
        Parses the XML.
        Parameters:
        is - the XML content as an input stream
        xmlTransformer - the XML transformer
        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 namespaces to force assign to each node. This may be needed for JAXB unmarshalling from XML -> POJO.
        Returns:
        the DOM model
        Throws:
        Exception - is thrown if error parsing