1 package net.sf.openrocket.file.simplesax;
3 import java.io.IOException;
5 import net.sf.openrocket.aerodynamics.WarningSet;
7 import org.xml.sax.InputSource;
8 import org.xml.sax.SAXException;
9 import org.xml.sax.XMLReader;
10 import org.xml.sax.helpers.XMLReaderFactory;
14 * A "simple SAX" XML reader. This system imposes the limit that an XML element may
15 * contain either textual (non-whitespace) content OR additional elements, but not
16 * both. This holds true for both the OpenRocket and RockSim design formats and the
17 * RockSim engine definition format.
19 * The actual handling is performed by subclasses of {@link ElementHandler}. The
20 * initial handler is provided to the {@link #readXML(InputSource, ElementHandler, WarningSet)}
23 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
25 public class SimpleSAX {
28 * Read a simple XML file.
30 * @param source the SAX input source.
31 * @param initialHandler the initial content handler.
32 * @param warnings a warning set to store warning (cannot be <code>null</code>).
33 * @throws IOException if an I/O exception occurs while reading.
34 * @throws SAXException if e.g. malformed XML is encountered.
36 public static void readXML(InputSource source, ElementHandler initialHandler,
37 WarningSet warnings) throws IOException, SAXException {
39 DelegatorHandler xmlhandler = new DelegatorHandler(initialHandler, warnings);
41 XMLReader reader = XMLReaderFactory.createXMLReader();
42 reader.setContentHandler(xmlhandler);
43 reader.setErrorHandler(xmlhandler);