public abstract class SaxParserUtil extends DefaultHandler
This class uses reflection to call subclass methods for each start and end element. The method names are _${element}Start and _${element}End. For example, for the following XML code:
<para>some text</para>
would cause the methods _paraStart(Attributes) and _paraEnd() to be called. The text between the two tags can be retrieved with the getCData() method.
Constructor and Description |
---|
SaxParserUtil()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] buf,
int offset,
int len)
Receive notification of character data (CDATA) inside an element.
|
void |
endElement(String namespaceURI,
String localName,
String qName)
Called for each element end tag.
|
void |
error(SAXParseException e)
Called for recoverable errors
|
void |
fatalError(SAXParseException e)
Called for recoverable errors
|
protected String |
getCData()
Return the value of character data (CDATA section) for current element.
|
URL |
getURL()
Return the URL of the last XML file parsed by this instance.
|
void |
parse(String urlStr)
Parse the given XML file.
|
void |
parse(URL url)
Parse the given XML file.
|
void |
parse(URL url,
InputStream in)
Parse an XML file from an already open input stream.
|
InputSource |
resolveEntity(String publicId,
String systemId)
This method tries to locate a local copy of the DTD as a JSky resource.
|
void |
startElement(String namespaceURI,
String localName,
String qName,
Attributes attrs)
Called for each element start tag.
|
void |
warning(SAXParseException e)
Called for XML parser warnings
|
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl
public SaxParserUtil()
public void parse(URL url)
url
- the URL for the XML filepublic void parse(String urlStr) throws MalformedURLException
urlStr
- the URL string for the XML fileMalformedURLException
public void parse(URL url, InputStream in)
url
- the URL for the XML file, for referencein
- the input stream for the given URLpublic URL getURL()
public InputSource resolveEntity(String publicId, String systemId)
resolveEntity
in interface EntityResolver
resolveEntity
in class DefaultHandler
Resources
public void fatalError(SAXParseException e) throws SAXParseException
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
SAXParseException
public void error(SAXParseException e) throws SAXParseException
error
in interface ErrorHandler
error
in class DefaultHandler
SAXParseException
public void warning(SAXParseException e) throws SAXParseException
warning
in interface ErrorHandler
warning
in class DefaultHandler
SAXParseException
public void startElement(String namespaceURI, String localName, String qName, Attributes attrs) throws SAXException
startElement
in interface ContentHandler
startElement
in class DefaultHandler
SAXException
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
endElement
in interface ContentHandler
endElement
in class DefaultHandler
SAXException
public void characters(char[] buf, int offset, int len) throws SAXException
characters
in interface ContentHandler
characters
in class DefaultHandler
SAXException
protected String getCData()
Copyright © 2023 Central Laboratory of the Research Councils. All Rights Reserved.