KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > org > xml > sax > XMLReader

org.xml.sax
Interface XMLReader

All Known Subinterfaces:
XMLFilter
All Known Implementing Classes:
ParserAdapter, XMLFilterImpl
See Also:
Top Examples, Source Code, Parser, parse, Reader, XMLReaderAdapter

ContentHandler getContentHandler()
See Also:
setContentHandler(org.xml.sax.ContentHandler)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


DTDHandler getDTDHandler()
See Also:
setDTDHandler(org.xml.sax.DTDHandler)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


EntityResolver getEntityResolver()
See Also:
setEntityResolver(org.xml.sax.EntityResolver)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


ErrorHandler getErrorHandler()
See Also:
setErrorHandler(org.xml.sax.ErrorHandler)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


Object getProperty(String name)
                   throws SAXNotRecognizedException,
                          SAXNotSupportedException
See Also:
setProperty(java.lang.String, java.lang.Object)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void parse(String systemId)
           throws IOException,
                  SAXException
See Also:
parse(org.xml.sax.InputSource)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void parse(InputSource input)
           throws IOException,
                  SAXException
See Also:
setErrorHandler(org.xml.sax.ErrorHandler), setContentHandler(org.xml.sax.ContentHandler), setDTDHandler(org.xml.sax.DTDHandler), setEntityResolver(org.xml.sax.EntityResolver), parse(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1919]Using SJSXP to Parse XML Documents
By Anonymous on 2007/08/14 16:28:09  Rate
Reading in XML documents with the SJSXP  ( SUN JAVA STREAMING XML PARSER )  is fairly easy. Most of the work is done through an object that implements the javax.xml.stream.XMLStreamReader interface. This interface represents a cursor that's moved across an XML document from beginning to end. A few things to keep in mind: the cursor always points to a single item, such as an element start-tag, a processing instruction, or a DTD declaration. Also, the cursor always moves forward  ( not backward ) , and you cannot perform any "look aheads" to see what's upcoming in the document. You can obtain an XMLStreamReader to read in XML from a file with the following snippet of code: 
  
  
    URL url = Class.forName ( "MyClassName" ) .getResource (  
            "sample.xml" ) ;             
    InputStream in = url.openStream (  ) ; 
    XMLInputFactory factory = XMLInputFactory.newInstance (  ) ; 
    XMLStreamReader parser = factory.createXMLStreamReader ( in ) ; 
  
  
 You can then iterate through the XML file with the following code: 
  
  
    while ( parser.hasNext (  )  )   {  
               
          eventType = parser.next (  ) ; 
          switch  ( eventType )   {  
  
  
               case START_ELEMENT: 
               // Do something 
               break; 
               case END_ELEMENT: 
               // Do something 
               break; 
               // And so on ... 
           }  
       }  
  
  
 The hasNext (  )  method in XMLStreamReader checks to see if there is another item available in the XML file. If there is one, you can use the next (  )  method to advance the cursor to the next item. The next (  )  method returns an integer code that indicates the type of grammatical construct  ( the item )  that it encountered.


void setContentHandler(ContentHandler handler)
See Also:
getContentHandler()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void setDTDHandler(DTDHandler handler)
See Also:
getDTDHandler()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void setEntityResolver(EntityResolver resolver)
See Also:
getEntityResolver()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void setErrorHandler(ErrorHandler handler)
See Also:
getErrorHandler()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void setFeature(String name,
                boolean value)
                throws SAXNotRecognizedException,
                       SAXNotSupportedException
See Also:
getFeature(java.lang.String)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


void setProperty(String name,
                 Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1943]engineer
By Sergei on 2007/11/23 03:01:23  Rate
setProperty ( String name, Object value )   
 Why Object? 
 How to send static publis String to Object  ( avoid reading from file ) 

Popular Tags