Class XMLTools


  • public class XMLTools
    extends Object
    Utility class for reading chunks of XML files and feeding them to SAX.
    Since:
    1.5
    Author:
    Richard Holland
    • Method Detail

      • readXMLChunk

        public static boolean readXMLChunk​(BufferedReader reader,
                                           DefaultHandler m_handler,
                                           String chunkToken)
                                    throws ParserConfigurationException,
                                           SAXException,
                                           IOException
        Attempts to read XML file in chunks, passing each chunk to a SAX parser. As each chunk is read into memory in a buffer, you need to ensure that each chunk is small enough to fit into available memory. Only one chunk is held in memory at any one time, and then only long enough for it to be parsed. When checking for the presence of further chunks, it'll only read up to 1000 chars further into the file, after which results will be unpredictable.
        Parameters:
        reader - the reader to read the XML from
        m_handler - the SAX parser to feed the XML to
        chunkToken - the token to read. The parser will locate the first instance of <chunkToken and will buffer all content, including the opening tag and up to and including the closing </chunkToken> tag. It will not currently handle <chunkToken/> instances, nor instances where more than one tag appears per line, or extra spaces appear between the angle brackets, slashes, and tag name of the tag we are searching for.
        Returns:
        true if there is another chunk left to read after this one, false if not.
        Throws:
        ParserConfigurationException - if there was a problem setting up the SAX parser.
        SAXException - if there was a problem parsing the XML.
        IOException - if there was a problem reading the XML from the reader.