com.lightdev.lib.xml.parser
Class XmlParser

java.lang.Object
  extended by com.lightdev.lib.xml.parser.XmlParser

public class XmlParser
extends Object

XmlParser is a parser for XML text

The parser does not support DOM, document type descriptions (DTDs) nor validation of XML against DTDs. It simply parses XML text and triggers a given instance of XmlParserCallback.

To use parsed contents in own applications a customized class that implements interface XmlParserCallback must be used.

Usage example:

 public class ExampleReader extends BufferedReader implements XmlParserCallback {
    public ExampleReader(Reader in) {
      super(in);
    }
    public void read(Object destination) throws IOException, IllegalCharacterException {
      XmlParser p = new XmlParser(this);
      String line = readLine();
      while(line != null) {
        p.parse(line);
        line = readLine();
      }
    }
    public void handleStartTag(String tagName, AttributeSet a) {
      System.out.println("handleStartTag, tagName='" + tagName + "'");
    }
    public void handleEndTag(String tagName) {
      System.out.println("handleEndTag, tagName='" + tagName + "'");
    }
    public void handleText(String text) {
      System.out.println("handleText, text='" + text + "'");
    }
  }
 

Version:
1, March 5, 2005
Author:
Ulrich Hilger, Light Development, http://www.lightdev.com, info@lightdev.com, published under the terms and conditions of the BSD License, for details see file license.txt in the distribution package of this software
See Also:
XmlParserCallback

Field Summary
static char altAttrValueBorder
           
static char attrNameEnd
          character indicating the start of an attribute value
static char attrStart
          character indicating the start of an attribute
static char attrValueBorder
          character indicating the start of an attribute value
static char commentEnd
          character indicating the end of a comment
static char commentStart
          character indicating the start of a comment
static char endTagStart
          character indicating the start of an end tag
static char exChar
          exclamation character
static char qChar
          question mark character
static char special
          character indicating special characters
static char specialEnd
          character indicating the end of a special character
static char tagEnd
          character indicating the end of a tag
static char tagStart
          character indicating the start of a tag
 
Constructor Summary
XmlParser(XmlParserCallback cb)
          construct a new XmlParser
 
Method Summary
 void parse(String data)
          parse a text portion by going through each character of the data string and by driving the XmlParserCallback according to the found data (start tags, attributes, end tags and content).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tagStart

public static final char tagStart
character indicating the start of a tag

See Also:
Constant Field Values

tagEnd

public static final char tagEnd
character indicating the end of a tag

See Also:
Constant Field Values

endTagStart

public static final char endTagStart
character indicating the start of an end tag

See Also:
Constant Field Values

qChar

public static final char qChar
question mark character

See Also:
Constant Field Values

exChar

public static final char exChar
exclamation character

See Also:
Constant Field Values

attrStart

public static final char attrStart
character indicating the start of an attribute

See Also:
Constant Field Values

attrValueBorder

public static final char attrValueBorder
character indicating the start of an attribute value

See Also:
Constant Field Values

altAttrValueBorder

public static final char altAttrValueBorder
See Also:
Constant Field Values

attrNameEnd

public static final char attrNameEnd
character indicating the start of an attribute value

See Also:
Constant Field Values

specialEnd

public static final char specialEnd
character indicating the end of a special character

See Also:
Constant Field Values

commentStart

public static final char commentStart
character indicating the start of a comment

See Also:
Constant Field Values

commentEnd

public static final char commentEnd
character indicating the end of a comment

See Also:
Constant Field Values

special

public static final char special
character indicating special characters

See Also:
Constant Field Values
Constructor Detail

XmlParser

public XmlParser(XmlParserCallback cb)
construct a new XmlParser

Parameters:
cb - the XmlParserCallback this parser calls to handle tags, attributes and content found
See Also:
XmlParserCallback
Method Detail

parse

public void parse(String data)
           throws IllegalCharacterException
parse a text portion by going through each character of the data string and by driving the XmlParserCallback according to the found data (start tags, attributes, end tags and content).

Parameters:
data - the data String to parse
Throws:
IllegalCharacterException
See Also:
XmlParserCallback