dap4/d4core/src/main/java/dap4/core/dmr/parser/bison/SaxEventHandler.java
public boolean parse(String document)
            throws SAXException
    {
        // Trim and strip any leading <?xml...?>
        StringBuilder doc = new StringBuilder(document.trim());
        int index = doc.indexOf("<?xml");
        if(index == 0) {
            index = doc.indexOf("?>");
            if(index < 0)
                throw new SAXException("Document has malformed <?xml...?> prefix");
            doc.delete(0,index+2);
            // remove any leading crlf
            while(doc.length() > 0 && "\r\n".indexOf(doc.charAt(0)) >= 0)
                doc.deleteCharAt(0);
            document = doc.toString();
        }
        this.document = document;
        // Create the sax parser that will drive us with events
        try {
            spf = SAXParserFactory.newInstance();
            spf.setValidating(false);
            spf.setNamespaceAware(true);
            spf.setFeature(LOAD_EXTERNAL_DTD, false);
            saxparser = spf.newSAXParser();
            // Set up for the parse
            input = new ByteArrayInputStream(document.getBytes(UTF8));
            saxparser.parse(input, this); //'this' is link to subclass parser
            return true;
        } catch (Exception e) {
            throw new SAXException(e);
        }
    }
public boolean parse(String document)
            throws SAXException
    {
        // Trim and strip any leading <?xml...?>
        StringBuilder doc = new StringBuilder(document.trim());
        int index = doc.indexOf("<?xml");
        if(index == 0) {
            index = doc.indexOf("?>");
            if(index < 0)
                throw new SAXException("Document has malformed <?xml...?> prefix");
            doc.delete(0,index+2);
            // remove any leading crlf
            while(doc.length() > 0 && "\r\n".indexOf(doc.charAt(0)) >= 0)
                doc.deleteCharAt(0);
            document = doc.toString();
        }
        this.document = document;
        // Create the sax parser that will drive us with events
        try {
            spf = SAXParserFactory.newInstance();
            spf.setValidating(false);
            spf.setNamespaceAware(true);
            spf.setFeature(LOAD_EXTERNAL_DTD, false);
            saxparser = spf.newSAXParser();
            // Set up for the parse
            input = new ByteArrayInputStream(document.getBytes(UTF8));
            saxparser.parse(input, this); //'this' is link to subclass parser
            return true;
        } catch (Exception e) {
            throw new SAXException(e);
        }
    }
public boolean parse ( String document ) throws SAXException { // Trim and strip any leading <?xml...?> StringBuilder doc = new StringBuilder ( document . trim ( ) ) ; int index = doc . indexOf ( "<?xml" ) ; if ( index == 0 ) { index = doc . indexOf ( "?>" ) ; if ( index < 0 ) throw new SAXException ( "Document has malformed <?xml...?> prefix" ) ; doc . delete ( 0 , index + 2 ) ; // remove any leading crlf while ( doc . length ( ) > 0 && "\r\n" . indexOf ( doc . charAt ( 0 ) ) >= 0 ) doc . deleteCharAt ( 0 ) ; document = doc . toString ( ) ; } this . document = document ; // Create the sax parser that will drive us with events try { spf = SAXParserFactory . newInstance ( ) ; spf . setValidating ( false ) ; spf . setNamespaceAware ( true ) ; spf . setFeature ( LOAD_EXTERNAL_DTD , false ) ; saxparser = spf . newSAXParser ( ) ; // Set up for the parse input = new ByteArrayInputStream ( document . getBytes ( UTF8 ) ) ; saxparser . parse ( input , this ) ; //'this' is link to subclass parser return true ; } catch ( Exception e ) { throw new SAXException ( e ) ; } }
Public API
Public API