Class 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.
    • 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)  
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        endPrefixMapping, fatalError, notationDecl, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ValidatingXMLParser

        public ValidatingXMLParser()
    • 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 interface org.xml.sax.ContentHandler
        Overrides:
        setDocumentLocator in class org.xml.sax.helpers.DefaultHandler
      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Overrides:
        startDocument in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXException
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class org.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 interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.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 interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.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 interface org.xml.sax.ContentHandler
        Overrides:
        characters in class org.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 interface org.xml.sax.ContentHandler
        Overrides:
        ignorableWhitespace in class org.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 interface org.xml.sax.ContentHandler
        Overrides:
        processingInstruction in class org.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 interface org.xml.sax.ErrorHandler
        Overrides:
        error in class org.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 interface org.xml.sax.ErrorHandler
        Overrides:
        warning in class org.xml.sax.helpers.DefaultHandler
        Throws:
        org.xml.sax.SAXParseException