Package ptolemy.configs.test
Class ValidatingXMLParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- ptolemy.configs.test.ValidatingXMLParser
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler
,org.xml.sax.DTDHandler
,org.xml.sax.EntityResolver
,org.xml.sax.ErrorHandler
public class ValidatingXMLParser extends org.xml.sax.helpers.DefaultHandler
A validating XML parser.Note that MoML files are not always valid XML because of the <configure> tag, so that tag should be removed.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Christopher Brooks
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ValidatingXMLParser.MoMLEntityResolver
Resolve an entity by checking for http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd and, if found, return the value of MoMLParser.MoML_1.dtd.
-
Constructor Summary
Constructors Constructor Description ValidatingXMLParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] buf, int offset, int len)
void
endDocument()
void
endElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName)
void
error(org.xml.sax.SAXParseException exception)
void
ignorableWhitespace(char[] buf, int offset, int len)
static void
main(java.lang.String[] args)
Parse an XML parser using a validating parser.static void
parse(java.lang.String fileName)
Parse an XML parser using a validating parser.void
processingInstruction(java.lang.String target, java.lang.String data)
void
setDocumentLocator(org.xml.sax.Locator l)
void
startDocument()
void
startElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName, org.xml.sax.Attributes attrs)
void
warning(org.xml.sax.SAXParseException exception)
-
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
Parse an XML parser using a validating parser. The DTD http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd is replaced with the value of MoMLParser.MoML_1.dtd.- Parameters:
args
- A single element array that names the xml file to be parsed. The file should have <configure>...<configure> removed. One workaround is to remove the configure tags with a script before validating, see $PTII/ptolemy/moml/test/removeconfigure. See also http://ptolemy.eecs.berkeley.edu/ptolemyII/ptIIfaq.htm#MoML
-
parse
public static void parse(java.lang.String fileName) throws java.lang.Throwable
Parse an XML parser using a validating parser. The DTD http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd is replaced with the value of MoMLParser.MoML_1.dtd.- Parameters:
fileName
- The xml file to be parsed. The file should have <configure>...<configure> removed.- Throws:
java.lang.Throwable
- If the XML is invalid XML.
-
setDocumentLocator
public void setDocumentLocator(org.xml.sax.Locator l)
- Specified by:
setDocumentLocator
in interfaceorg.xml.sax.ContentHandler
- Overrides:
setDocumentLocator
in classorg.xml.sax.helpers.DefaultHandler
-
startDocument
public void startDocument() throws org.xml.sax.SAXException
- Specified by:
startDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocument
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endDocument
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName, org.xml.sax.Attributes attrs) throws org.xml.sax.SAXException
- Specified by:
startElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
startElement
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String sName, java.lang.String qName) throws org.xml.sax.SAXException
- Specified by:
endElement
in interfaceorg.xml.sax.ContentHandler
- Overrides:
endElement
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
characters
public void characters(char[] buf, int offset, int len) throws org.xml.sax.SAXException
- Specified by:
characters
in interfaceorg.xml.sax.ContentHandler
- Overrides:
characters
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] buf, int offset, int len) throws org.xml.sax.SAXException
- Specified by:
ignorableWhitespace
in interfaceorg.xml.sax.ContentHandler
- Overrides:
ignorableWhitespace
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
processingInstruction
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
- Specified by:
processingInstruction
in interfaceorg.xml.sax.ContentHandler
- Overrides:
processingInstruction
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXException
-
error
public void error(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXParseException
- Specified by:
error
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
error
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXParseException
-
warning
public void warning(org.xml.sax.SAXParseException exception) throws org.xml.sax.SAXParseException
- Specified by:
warning
in interfaceorg.xml.sax.ErrorHandler
- Overrides:
warning
in classorg.xml.sax.helpers.DefaultHandler
- Throws:
org.xml.sax.SAXParseException
-
-