Search in sources :

Example 16 with SAXParser

use of javax.xml.parsers.SAXParser in project robovm by robovm.

the class SimpleParserTest method testWorkingFile2.

public void testWorkingFile2() throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(false);
    factory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
    SAXParser parser = factory.newSAXParser();
    parser.getXMLReader().setContentHandler(contentHandler);
    parser.parse(getClass().getResourceAsStream("/SimpleParserTest.xml"), (DefaultHandler) null);
    assertFalse(parser.isNamespaceAware());
    assertEquals("The:quick,brown:fox", instructions.toString());
    assertEquals("t:stuff,nestedStuff,nestedStuff,nestedStuff", elements2.toString());
    assertEquals("Some text here,some more here...", text.toString());
    assertEquals("eins", attributes2.get("one"));
    assertEquals("zwei", attributes2.get("two"));
    assertEquals("drei", attributes2.get("three"));
    assertEquals(0, namespaces2.size());
}
Also used : SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 17 with SAXParser

use of javax.xml.parsers.SAXParser in project robovm by robovm.

the class XercesHTML2DocumentBuilderFactory method load.

public Document load(java.net.URL url) throws DOMTestLoadException {
    Document doc = null;
    try {
        SAXParser parser = factory.newSAXParser();
        HTMLHandler handler = new HTMLHandler(htmlBuilderConstructor, getHTMLDocumentMethod);
        parser.parse(url.toString(), handler);
        doc = handler.getHTMLDocument();
    } catch (Exception ex) {
        throw new DOMTestLoadException(ex);
    }
    return doc;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) Document(org.w3c.dom.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 18 with SAXParser

use of javax.xml.parsers.SAXParser in project robovm by robovm.

the class XercesHTMLDocumentBuilderFactory method load.

public Document load(java.net.URL url) throws DOMTestLoadException {
    Document doc = null;
    try {
        SAXParser parser = factory.newSAXParser();
        HTMLHandler handler = new HTMLHandler(htmlBuilderConstructor, getHTMLDocumentMethod);
        parser.parse(url.toString(), handler);
        doc = handler.getHTMLDocument();
    } catch (Exception ex) {
        throw new DOMTestLoadException(ex);
    }
    return doc;
}
Also used : SAXParser(javax.xml.parsers.SAXParser) Document(org.w3c.dom.Document) InvocationTargetException(java.lang.reflect.InvocationTargetException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 19 with SAXParser

use of javax.xml.parsers.SAXParser in project robovm by robovm.

the class SAXParserTest method initFiles.

public void initFiles() throws Exception {
    // we differntiate between a validating and a non validating parser
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        validating = parser.isValidating();
    } catch (Exception e) {
        fail("could not obtain a SAXParser");
    }
    String tmpPath = System.getProperty("java.io.tmpdir");
    // nwf = not well formed, wf = well formed
    list_wf = new File[] { new File(tmpPath + "/" + SAXParserTestSupport.XML_WF + "staff.xml") };
    list_nwf = new File[] { new File(tmpPath + "/" + SAXParserTestSupport.XML_NWF + "staff.xml") };
    list_out_dh = new File[] { new File(tmpPath + "/" + SAXParserTestSupport.XML_WF_OUT_DH + "staff.out") };
    list_out_hb = new File[] { new File(tmpPath + "/" + SAXParserTestSupport.XML_WF_OUT_HB + "staff.out") };
    list_wf[0].deleteOnExit();
    list_nwf[0].deleteOnExit();
    list_out_hb[0].deleteOnExit();
    list_out_dh[0].deleteOnExit();
    Support_Resources.copyLocalFileto(list_wf[0], getResource(SAXParserTestSupport.XML_WF + "staff.xml"));
    Support_Resources.copyLocalFileto(new File(tmpPath + "/" + SAXParserTestSupport.XML_WF + "staff.dtd"), getResource(SAXParserTestSupport.XML_WF + "staff.dtd"));
    Support_Resources.copyLocalFileto(list_nwf[0], getResource(SAXParserTestSupport.XML_NWF + "staff.xml"));
    Support_Resources.copyLocalFileto(new File(tmpPath + "/" + SAXParserTestSupport.XML_NWF + "staff.dtd"), getResource(SAXParserTestSupport.XML_NWF + "staff.dtd"));
    Support_Resources.copyLocalFileto(list_out_dh[0], getResource(SAXParserTestSupport.XML_WF_OUT_DH + "staff.out"));
    Support_Resources.copyLocalFileto(list_out_hb[0], getResource(SAXParserTestSupport.XML_WF_OUT_HB + "staff.out"));
}
Also used : SAXParser(javax.xml.parsers.SAXParser) File(java.io.File) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException)

Example 20 with SAXParser

use of javax.xml.parsers.SAXParser in project platform_frameworks_base by android.

the class XMLParser method parse.

public XMLNode parse(String text) throws IOException, SAXException {
    if (TextUtils.isEmpty(text)) {
        throw new IOException("XML string not provided");
    }
    // Reset pointers.
    mRoot = null;
    mCurrent = null;
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        parser.parse(new InputSource(new StringReader(text)), this);
        return mRoot;
    } catch (ParserConfigurationException pce) {
        throw new SAXException(pce);
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

SAXParser (javax.xml.parsers.SAXParser)235 SAXParserFactory (javax.xml.parsers.SAXParserFactory)142 SAXException (org.xml.sax.SAXException)112 InputSource (org.xml.sax.InputSource)95 IOException (java.io.IOException)80 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)71 DefaultHandler (org.xml.sax.helpers.DefaultHandler)37 XMLReader (org.xml.sax.XMLReader)36 File (java.io.File)35 ByteArrayInputStream (java.io.ByteArrayInputStream)28 StringReader (java.io.StringReader)27 InputStream (java.io.InputStream)24 Attributes (org.xml.sax.Attributes)22 SAXSource (javax.xml.transform.sax.SAXSource)17 SAXParseException (org.xml.sax.SAXParseException)17 ArrayList (java.util.ArrayList)13 JAXBContext (javax.xml.bind.JAXBContext)12 Unmarshaller (javax.xml.bind.Unmarshaller)12 FileNotFoundException (java.io.FileNotFoundException)10 ValidationEvent (javax.xml.bind.ValidationEvent)9