Class XMLValidator


  • public final class XMLValidator
    extends java.lang.Object
    Validate XML files with a given DTD or XML Schema (XSD).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  XMLValidator.ErrorHandler
      XML handler that throws exception on error and warning, does nothing otherwise.
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLValidator()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkSimpleXMLString​(java.lang.String xml)
      Check some limits of our simplified XML output.
      private javax.xml.validation.Validator getValidator​(java.net.URL xmlSchema)  
      private static javax.xml.transform.Source mergeIntoSource​(java.io.InputStream baseXmlStream, java.io.InputStream xmlStream)  
      private void validateInternal​(java.lang.String xml, java.lang.String dtdPath, java.lang.String docType)  
      private void validateInternal​(javax.xml.transform.Source xmlSrc, java.net.URL xmlSchema)  
      void validateStringWithXmlSchema​(java.lang.String xml, java.lang.String xmlSchemaPath)
      Validate XML file using the given XSD.
      void validateWithDtd​(java.lang.String filename, java.lang.String dtdPath, java.lang.String docType)
      Validate XML file in classpath with the given DTD.
      void validateWithXmlSchema​(java.lang.String filename, java.lang.String xmlSchemaPath)
      Validate XML file using the given XSD.
      void validateWithXmlSchema​(java.lang.String baseFilename, java.lang.String filename, java.lang.String xmlSchemaPath)
      Validate XML file using the given XSD.
      void validateXMLString​(java.lang.String xml, java.lang.String dtdFile, java.lang.String docType)
      Validate XML with the given DTD.
      • Methods inherited from class java.lang.Object

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

      • XMLValidator

        public XMLValidator()
    • Method Detail

      • checkSimpleXMLString

        public void checkSimpleXMLString​(java.lang.String xml)
                                  throws java.io.IOException
        Check some limits of our simplified XML output.
        Throws:
        java.io.IOException
      • validateXMLString

        public void validateXMLString​(java.lang.String xml,
                                      java.lang.String dtdFile,
                                      java.lang.String docType)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      javax.xml.parsers.ParserConfigurationException
        Validate XML with the given DTD. Throws exception on error.
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
      • validateWithDtd

        public void validateWithDtd​(java.lang.String filename,
                                    java.lang.String dtdPath,
                                    java.lang.String docType)
                             throws java.io.IOException
        Validate XML file in classpath with the given DTD. Throws exception on error.
        Throws:
        java.io.IOException
      • validateWithXmlSchema

        public void validateWithXmlSchema​(java.lang.String filename,
                                          java.lang.String xmlSchemaPath)
                                   throws java.io.IOException
        Validate XML file using the given XSD. Throws an exception on error.
        Parameters:
        filename - File in classpath to validate
        xmlSchemaPath - XML schema file in classpath
        Throws:
        java.io.IOException
      • validateWithXmlSchema

        public void validateWithXmlSchema​(java.lang.String baseFilename,
                                          java.lang.String filename,
                                          java.lang.String xmlSchemaPath)
                                   throws java.io.IOException
        Validate XML file using the given XSD. Throws an exception on error.
        Parameters:
        baseFilename - File to prepend common parts (unification) from before validating main file
        filename - File in classpath to validate
        xmlSchemaPath - XML schema file in classpath
        Throws:
        java.io.IOException
      • mergeIntoSource

        private static javax.xml.transform.Source mergeIntoSource​(java.io.InputStream baseXmlStream,
                                                                  java.io.InputStream xmlStream)
                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • validateStringWithXmlSchema

        public void validateStringWithXmlSchema​(java.lang.String xml,
                                                java.lang.String xmlSchemaPath)
                                         throws java.io.IOException
        Validate XML file using the given XSD. Throws an exception on error.
        Parameters:
        xml - the XML string to be validated
        xmlSchemaPath - XML schema file in classpath
        Throws:
        java.io.IOException
        Since:
        2.3
      • validateInternal

        private void validateInternal​(java.lang.String xml,
                                      java.lang.String dtdPath,
                                      java.lang.String docType)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException,
                                      javax.xml.parsers.ParserConfigurationException
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
        javax.xml.parsers.ParserConfigurationException
      • validateInternal

        private void validateInternal​(javax.xml.transform.Source xmlSrc,
                                      java.net.URL xmlSchema)
                               throws org.xml.sax.SAXException,
                                      java.io.IOException
        Throws:
        org.xml.sax.SAXException
        java.io.IOException
      • getValidator

        private javax.xml.validation.Validator getValidator​(java.net.URL xmlSchema)
                                                     throws org.xml.sax.SAXException
        Throws:
        org.xml.sax.SAXException