Package javax.xml.parsers

Examples of javax.xml.parsers.SAXParserFactory


   */
  private Scene parseXMLStream(InputStream in,
                               URL baseUrl) throws IOException {
    try {
      SceneBase scene = new SceneBase();
      SAXParserFactory factory = SAXParserFactory.newInstance();
      factory.setValidating(false);
      SAXParser saxParser = factory.newSAXParser();
      saxParser.parse(in, new DAEHandler(scene, baseUrl));
      return scene;
    } catch (ParserConfigurationException ex) {
      IOException ex2 = new IOException("Can't parse XML stream");
      ex2.initCause(ex);
View Full Code Here


    public static XmlNode parse(InputSource in) {
        long startTime = System.currentTimeMillis();

        XmlParser handler = new XmlParser();
        try {
            SAXParserFactory parserFactory = SAXParserFactory.newInstance();
            parserFactory.setValidating(false);
            parserFactory.setNamespaceAware(false);

            SAXParser parser = parserFactory.newSAXParser();

            // call parsing
            parser.parse(in, handler);

            log.info("XML parsed in " + (System.currentTimeMillis() - startTime) + "ms.");
View Full Code Here

        try
        {
            if (parser == null)
            {
                // Create a SAXParser (use JDK parser for now)
                SAXParserFactory factory = SAXParserFactory.newInstance();
                factory.setValidating(validate);
                factory.setNamespaceAware(validate);
                if (validate)
                {
                    try
                    {
                        Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
                            getRegisteredSchemas(mgr.getNucleusContext().getPluginManager()));
                        if (schema != null)
                        {
                            try
                            {
                                factory.setSchema(schema);
                            }
                            catch (UnsupportedOperationException e)
                            {
                                // may happen in conflict of JDK 1.5 and older xml libraries (xerces)
                                NucleusLogger.METADATA.info(e.getMessage());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        // Cannot validate since no SchemaFactory could be loaded?
                        NucleusLogger.METADATA.info(e.getMessage());
                    }

                    // Xerces (if in CLASSPATH) needs this for validation (of XSD)
                    try
                    {
                        factory.setFeature("http://apache.org/xml/features/validation/schema", true);
                    }
                    catch (Exception e)
                    {
                        NucleusLogger.METADATA.info(e.getMessage());
                    }
                }
                parser = factory.newSAXParser();
            }

            // Generate the default handler to process the metadata
            DefaultHandler handler = null;
            EntityResolver entityResolver = null;
View Full Code Here

        String wsdlSystemId = wsdlUri.toExternalForm();
        DOMSource source = new DOMSource(wsdl);
        source.setSystemId(wsdlSystemId);

        LocalController controller = new LocalController();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        wsdlgrammar = WSDLSchemaReader.read(source, factory, controller);
        schema = new W3CSchema(wsdlgrammar);
  }
View Full Code Here

        final String XML =
            "<!DOCTYPE root PUBLIC '//some//public//id' 'no-such-thing.dtd'>\n"
            +"<root />"
            ;

        SAXParserFactory spf = new WstxSAXParserFactory();
        spf.setNamespaceAware(true);
        SAXParser sp = spf.newSAXParser();
        DefaultHandler h = new DefaultHandler();

        /* First: let's verify that we get an exception for
         * unresolved reference...
         */
        try {
            sp.parse(new InputSource(new StringReader(XML)), h);
        } catch (SAXException e) {
            verifyException(e, "No such file or directory");
        }

        // And then with dummy resolver; should work ok now
        sp = spf.newSAXParser();
        sp.getXMLReader().setEntityResolver(new MyResolver("   "));
        h = new DefaultHandler();
        try {
            sp.parse(new InputSource(new StringReader(XML)), h);
        } catch (SAXException e) {
View Full Code Here

    public void doTestSimple(boolean ns, boolean useReader)
        throws Exception
    {
        // no need to test JAXP introspection...
        SAXParserFactory spf = new WstxSAXParserFactory();
        spf.setNamespaceAware(ns);
        SAXParser sp = spf.newSAXParser();
        MyHandler h = new MyHandler();

        InputSource src;

        if (useReader) {
View Full Code Here

    @SuppressWarnings("deprecation")
  protected void test(File file)
        throws Exception
    {
        //SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParserFactory spf = new WstxSAXParserFactory();
        spf.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
        SAXParser sp = spf.newSAXParser();
        MyContentHandler h = new MyContentHandler();
        sp.setProperty(SAXProperty.LEXICAL_HANDLER.toString(), /*DeclHandler*/h);
        // This shouldn't be needed -- nor seems to work for Xerces?
        //sp.getXMLReader().setEntityResolver(h);
        InputStream in = new FileInputStream(file);
View Full Code Here

                                       IOException
    {
        SAXParser localParser = null;
        if ( this.parser == null )
        {
            SAXParserFactory factory = SAXParserFactory.newInstance( );
            factory.setNamespaceAware( true );

            String isValidatingString = System.getProperty( "drools.schema.validating" );
            if ( System.getProperty( "drools.schema.validating" ) != null )
            {
                this.isValidating = Boolean.getBoolean( "drools.schema.validating" );
            }

            if ( this.isValidating == true )
            {
                factory.setValidating( true );
                try
                {
                    localParser = factory.newSAXParser( );
                }
                catch ( ParserConfigurationException e )
                {
                    throw new RuntimeException( e.getMessage( ) );
                }

                try
                {
                    localParser.setProperty( JAXP_SCHEMA_LANGUAGE,
                                             W3C_XML_SCHEMA );
                }
                catch ( SAXNotRecognizedException e )
                {
                    boolean hideWarnings = Boolean.getBoolean( "drools.schema.hidewarnings" );
                    if ( !hideWarnings )
                    {
                        System.err.println( "Your SAX parser is not JAXP 1.2 compliant - turning off validation." );
                    }
                    localParser = null;
                }
            }

            if ( localParser == null )
            {
                // not jaxp1.2 compliant so turn off validation
                try
                {
                    this.isValidating = false;
                    factory.setValidating( this.isValidating );
                    localParser = factory.newSAXParser( );
                }
                catch ( ParserConfigurationException e )
                {
                    throw new RuntimeException( e.getMessage( ) );
                }
View Full Code Here

   */
  protected List<URI> load(final InputStream in) throws SAXException, IOException {
    SAXParser saxParser;

    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      saxParser = factory.newSAXParser();
    } catch (final ParserConfigurationException ex) {
      throw new SAXException(ex);
    }

    // Parse the XML
View Full Code Here

 

  public List<DefaultItem> load(final URI uri) throws SAXException {
    list = new LinkedList<DefaultItem>();
    // Use the default (non-validating) parser
    final SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
      // Parse the input
      final SAXParser saxParser = factory.newSAXParser();

      final InputStream is = ItemsXMLLoader.class.getResourceAsStream(uri.getPath());

      if (is == null) {
        throw new FileNotFoundException("cannot find resource '" + uri
View Full Code Here

TOP

Related Classes of javax.xml.parsers.SAXParserFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.