cds.xml
Class XMLParser

java.lang.Object
  extended by cds.xml.XMLParser

public final class XMLParser
extends java.lang.Object

XML parser. Simple XML parser for well-formed XML documents in ASCII, without validation Resolves automatically & " ' < >. Compacts blanks in one space (doesn't take into account SPACE XMl declaration. Assumes that the XML document begins with or . It uses 3 methodes to interact with a XML event consumer (similar to the XML SAX interface) -> startElement(), endElement() and characters() but the startElement() send an Hashtable for the tag parameters instead of the AttrList SAX object ==> See the XmlConsumer java interface to have an example of usage The in(nameList) method allows one to know at any time if the current parser state correspond to a particular XML levels

Version:
1.7 juin 07 gère les CDATA dans les tags, 1.6 oct 05 gère (ou plutôt ignore) les namespace VOTable + encodage correcte, 1.5 7 juillet 05 parse(dis,endTag) pour un parsing partiel, 1.4 19 jan 01 mode 5 in getString fixed, 1.3 27 apr 00 Doesn't transmit prefix, 1.2 12 apr 00 Take into account large escape sections, 1.1 13 mar 00 Take into account more XML errors., 1.0 03 sep 99 Creation
Author:
P.Fernique [CDS]

Field Summary
 int nstack
           
 
Constructor Summary
XMLParser(XMLConsumer ac)
          Create a new XMLParser object
XMLParser(XMLConsumer ac, boolean withStack)
           
 
Method Summary
 int getDepth()
           
 java.lang.String getError()
          Return the error report.
 java.util.Stack getStack()
          Return the stack of the tag name.
 byte[] getUnreadBuffer()
          Retourne les caractères non lus du buffer courant, ou null si lecture terminée
 boolean in(java.lang.String nameList)
          Return true if the tag name list in parameter is found in the XML stack (with the same order) and ends with the last tag name in the list.
 boolean parse(MyInputStream dis)
          Launch the XML parsing.
 boolean parse(MyInputStream dis, java.lang.String endTag)
          Lancement du parsing XML pour une sous-section.
static java.lang.String XMLDecode(java.lang.String s)
          Decode XML macros
static java.lang.String XMLEncode(java.lang.String s)
          Encode XML macros
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nstack

public int nstack
Constructor Detail

XMLParser

public XMLParser(XMLConsumer ac)
Create a new XMLParser object

Parameters:
ac - an object implementing the XMLConsumer interface
withStack - true si on gère une pile des tags (méthode in() et getStack() possible)

XMLParser

public XMLParser(XMLConsumer ac,
                 boolean withStack)
Method Detail

parse

public boolean parse(MyInputStream dis)
              throws java.lang.Exception
Launch the XML parsing. In case of errors, the report is accessible by getError()

Parameters:
dis - the input stream
Returns:
true or false according to the parsing result
Throws:
java.lang.Exception

parse

public boolean parse(MyInputStream dis,
                     java.lang.String endTag)
              throws java.lang.Exception
Lancement du parsing XML pour une sous-section. Attention, on ne ferme pas le flux En cas d'erreur, utiliser getError()

Parameters:
dis - le stream à parser
endTag - le TAG XML qui déterminera la fin du parsing partiel
Returns:
true ou false suivant le parsing
Throws:
java.lang.Exception

getStack

public java.util.Stack getStack()
                         throws java.lang.Exception
Return the stack of the tag name.

Returns:
The stack of the XML tag name
Throws:
java.lang.Exception

getDepth

public int getDepth()

in

public boolean in(java.lang.String nameList)
           throws java.lang.Exception
Return true if the tag name list in parameter is found in the XML stack (with the same order) and ends with the last tag name in the list.

Parameters:
nameList - List of tag names, separated by spaces
Returns:
true if all names are found in the XML stack respecting the same order
Throws:
java.lang.Exception

getError

public java.lang.String getError()
Return the error report.

Returns:
The string containing the error report or null if there isn't

XMLEncode

public static java.lang.String XMLEncode(java.lang.String s)
Encode XML macros

Parameters:
s - the string to encode
Returns:
the string encoded

XMLDecode

public static java.lang.String XMLDecode(java.lang.String s)
Decode XML macros

Parameters:
s - the string to decode
Returns:
the string decoded, null if macro error

getUnreadBuffer

public byte[] getUnreadBuffer()
Retourne les caractères non lus du buffer courant, ou null si lecture terminée



Copyright © 2009 UDS/CNRS