Showing posts with label parsers. Show all posts
Showing posts with label parsers. Show all posts

Saturday, January 22, 2011

Parsing using javascript

SAX parser links:
http://code.google.com/p/jssaxparser/

Dom parser links:
http://www.w3schools.com/Dom/dom_parser.asp

Sunday, November 21, 2010

SAX Example

 Sample s=new Sample();  
 SAXParserFactory factory = SAXParserFactory.newInstance();  
 SAXParser saxParser = factory.newSAXParser();  
 saxParser.parse("Have to give some class object(consider as Sample.java)", inputStream);  
 inputStream.close();  

 public class Sample extends DefaultHandler{  
      public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException   
      {  
           // This function invokes when parser reads the starting tag  
           // qName is element name  
           // below command gets the value of the Attribute "name"  
          attributes.getValue("name");    
      }  
      public void endElement(String uri, String localName, String qName) throws SAXException {  
           // This function is invoked when the parser reads the ending tag  
      }  
      public void characters(char[] chars, int start, int length) throws SAXException {  
           // Used to read the cdata  
          String s=new String(chars, start,length); // to read CDATA     
      }  
           //Put this line in any of the above method to voluntary exit the
           //parsing  "throw new DoneParsingException();"
 }