KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > xml > parsers > SAXParserFactory

javax.xml.parsers
Class SAXParserFactory

java.lang.Object
  extended by javax.xml.parsers.SAXParserFactory
See Also:
Top Examples, Source Code

public abstract boolean getFeature(String name)
                            throws ParserConfigurationException,
                                   SAXNotRecognizedException,
                                   SAXNotSupportedException
See Also:
XMLReader.getProperty(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Schema getSchema()
See Also:
UnsupportedOperationException, SAXParserFactory, setSchema(Schema)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isNamespaceAware()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isValidating()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isXIncludeAware()
See Also:
UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static SAXParserFactory newInstance()
See Also:
FactoryConfigurationError, DocumentBuilder
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract SAXParser newSAXParser()
                                throws ParserConfigurationException,
                                       SAXException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[488]Simple parse
By Erin on 2003/11/04 08:32:13  Rate
package simpleparse; 
  
  
 import javax.xml.parsers.SAXParserFactory; 
 import javax.xml.parsers.SAXParser; 
  
  
 import org.xml.sax.helpers.DefaultHandler; 
  
  
 public class SimpleParse 
  {  
   private static void main ( String argv [  ]  )  
    {  
     SAXParserFactory factory = SAXParserFactory.newInstance (  ) ; 
  
  
     try 
      {  
       SAXParser saxParser = factory.newSAXParser (  ) ; 
       saxParser.parse ( "book.xml", new DefaultHandler (  )  ) ; 
      }  
     catch  ( Throwable t )  
      {  
       t.printStackTrace (  ) ; 
      }  
     System.exit ( 0 ) ; 
    }  
  } 


protected SAXParserFactory()
See Also:
newInstance()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public abstract void setFeature(String name,
                                boolean value)
                         throws ParserConfigurationException,
                                SAXNotRecognizedException,
                                SAXNotSupportedException
See Also:
NullPointerException, SAXParser, ErrorHandler.fatalError(SAXParseException exception), XMLConstants.FEATURE_SECURE_PROCESSING
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1575]Builds a SAX parser and queries it for supported features
By Anonymous on 2005/11/04 20:23:08  Rate
import javax.xml.parsers.*; 
 import org.xml.sax.*; 
 import org.w3c.dom.*; 
  
  
 /** 
 This application class builds a SAX parser and queries it for supported  
 features, and reports the results.   
 It then checks each feature that is not turned on to see if it 
 can be turned on, and reports if so. 
  
  
 */
 
 public class ParserTest 
  {  
     public static void main  ( String [  ]  args )  
      {  
         final String [  ]  SAXFeatures = 
          {  
             "validation", 
             "external-general-entities", 
             "external-parameter-entities", 
             "namespaces", 
             "namespace-prefixes", 
             "string-interning" 
          } ; 
          
         try 
          {  
             SAXParserFactory factory = SAXParserFactory.newInstance  (  ) ; 
             System.out.println  ( "SAX parser factory class: " + 
                 factory.getClass  (  ) .getName  (  )  ) ; 
             System.out.println  (  ) ; 
              
             System.out.println  ( "SAX Features:" ) ; 
             for  ( int s = 0; s  <  SAXFeatures.length; ++s )  
              {  
                 System.out.print  ( " " + SAXFeatures [ s ]  + ": " ) ; 
                 try 
                  {  
                     boolean hasFeature = factory.getFeature  
                          ( "http://xml.org/sax/features/" + SAXFeatures [ s ]  ) ; 
                     System.out.print  ( "" + hasFeature + "." ) ; 
                      
                     if  ( !hasFeature )  try 
                      {  
                         factory.setFeature 
                              ( "http://xml.org/sax/features/" + SAXFeatures [ s ] ,  
                                 true ) ; 
                         System.out.print  ( "   ( Can enable. ) " ) ; 
                      }  
                     catch  ( SAXException ex )  
                      {  
                      }  
                  }  
                 catch  ( SAXNotRecognizedException ex )  
                  {  
                     System.out.print  ( "not recognized." ) ; 
                  }  
                  
                 System.out.println  (  ) ; 
              }  
             System.out.println  (  ) ; 
          }  
         catch  ( Exception ex )  
          {  
             ex.printStackTrace  (  ) ; 
          }  
      }  
  }  
  
  
 


[1578]Demonstration of the effects of the namespace features for a SAX application
By Anonymous on 2005/11/04 20:23:08  Rate
import java.io.*; 
 import javax.xml.parsers.*; 
 import org.xml.sax.*; 
 import org.xml.sax.helpers.*; 
  
  
 /** 
 A simple demonstration of the effects of the namespace features for a SAX 
 application. With both features set to  < code > true < /code >  every element name 
 in the source document is echoed to the console as a triplet of the form: 
 */
 
 public class NamespaceTest 
     extends DefaultHandler 
  {  
     /** 
     Gets a SAX parser factory, and sets the  < b > namespaces < /b >  
     property to true, and parses the 
     file whose name is passed on the command line. 
     */
 
     public static void main  ( String [  ]  args )  
      {  
         try 
          {  
             SAXParserFactory factory = SAXParserFactory.newInstance  (  ) ; 
             try 
              {  
                 factory.setFeature 
                      ( "http://xml.org/sax/features/namespaces", true ) ; 
                 factory.setFeature 
                      ( "http://xml.org/sax/features/namespace-prefixes", true ) ; 
              }  
             catch  ( SAXException ex )  
              {  
                 ex.printStackTrace  (  ) ; 
              }  
              
             SAXParser parser = factory.newSAXParser  (  ) ; 
             if  ( args.length != 0 )  
                 parser.parse  ( new File  ( args [ 0 ]  ) , new NamespaceTest  (  )  ) ; 
          }  
         catch  ( Exception ex )  
          {  
             ex.printStackTrace  (  ) ; 
          }  
      }  
      
     /** 
     Echoes the parameters for URI, name, and qName to the console. 
     */
 
     public void startElement  
              ( String URI, String name, String qName, Attributes attributes )   
         throws SAXException  
      {  
         System.out.println  ( " { " + URI + " } " + name + "  ( " + qName + " ) " ) ; 
      }  
  }  
  
  
 


public void setNamespaceAware(boolean awareness)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setSchema(Schema schema)
See Also:
UnsupportedOperationException, SAXParser, SAXException, isValidating(), ErrorHandler
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setValidating(boolean validating)
See Also:
setSchema(Schema)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setXIncludeAware(boolean state)
See Also:
UnsupportedOperationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags