Validate an XML file.
491685
def validate_xml(file):
    """"""
    max_file_size = current_app.config.get(
        'PREVIEWER_MAX_FILE_SIZE_BYTES', 1 * 1024 * 1024)
    if file.size > max_file_size:
        return False

    with file.open() as fp:
        try:
            content = fp.read().decode('utf-8')
            xml.dom.minidom.parseString(content)
            return True
        except:
            return False
1030373
private void validateXMLSchema(InputStream objectAsStream, DOValidatorXMLSchema xsv)
            throws ObjectValidityException, GeneralException {

        try {
            xsv.validate(objectAsStream);
        } catch (ObjectValidityException e) {
            logger.error("VALIDATE: ERROR - failed XML Schema validation.", e);
            throw e;
        } catch (Exception e) {
            logger.error("VALIDATE: ERROR - failed XML Schema validation.", e);
            throw new ObjectValidityException("[DOValidatorImpl]: validateXMLSchema. "
                    + e.getMessage());
        }
        logger.debug("VALIDATE: SUCCESS - passed XML Schema validation.");
    }
137762
def validate(self, r):
        '''
        
        '''
        if self.show_invalid:
            r.valid = True
        elif r.valid:
            if not r.description:
                r.valid = False

            if r.size and (r.size + r.offset) > r.file.size:
                r.valid = False

            if r.jump and (r.jump + r.offset) > r.file.size:
                r.valid = False

            if hasattr(r, "location") and (r.location != r.offset):
                r.valid = False

        if r.valid:
            # Don't keep displaying signatures that repeat a bunch of times
            # (e.g., JFFS2 nodes)
            if r.id == self.one_of_many:
                r.display = False
            elif r.many:
                self.one_of_many = r.id
            else:
                self.one_of_many = None
617822
private boolean validate(DefinitionsDocument defdoc) {
        List<XmlError> errorList = new ArrayList<>();
        XmlOptions options = new XmlOptions().setSavePrettyPrint().setSavePrettyPrintIndent(2)
                .setSaveAggressiveNamespaces();
        options.setErrorListener(errorList);

        System.out.println("!--toString---");
        System.out.println(defdoc.toString());
        boolean valid = defdoc.validate(options);
        System.out.println("Document is " + (valid ? "valid" : "invalid"));
        if (!valid) {
            for (int i = 0; i < errorList.size(); i++) {
                XmlError error = errorList.get(i);

                System.out.println("\n");
                System.out.println("Message: " + error.getMessage() + "\n");
                System.out.println(
                        "Location of invalid XML: " + error.getCursorLocation().xmlText() + "\n");
            }
        }
        return valid;
    }
576059
def validate(self):
        """"""
        validator = Draft4Validator(self.SCHEMA)
        if not validator.is_valid(self.config):
            for err in validator.iter_errors(self.config):
                LOGGER.error(str(err.message))
            validator.validate(self.config)
1139621
public void validate() {
        if (null != failedNodesfile && failedNodesfile.getName().startsWith("${") && failedNodesfile.getName()
                .endsWith("}")) {
            failedNodesfile=null;
        }
    }
332459
protected void validateModuleFile() {

        try {
            m_importFile.loadAndValidate();
            String importSite = m_importFile.getModule().getImportSite();
            if (importSite != null) {
                getSiteSelector().setEnabled(false);
                getSiteSelector().setValue(importSite);
            }
            getOkButton().setEnabled(true);
        } catch (Exception e) {
            LOG.info(e.getLocalizedMessage(), e);
            m_importFile = null;
            getOkButton().setEnabled(false);
            CmsErrorDialog.showErrorDialog(e);

        }
    }
462110
def validate(self, formats_dir="../formats/"):
        """"""
        #TODO: download XSD from web
        if self.inline:
            xmlschema = ElementTree.XMLSchema(ElementTree.parse(StringIO("\n".join(open(formats_dir+"dcoi-dsc.xsd").readlines()))))
            xmlschema.assertValid(self.tree)
            #return xmlschema.validate(self)
        else:
            xmlschema = ElementTree.XMLSchema(ElementTree.parse(StringIO("\n".join(open(formats_dir+"dutchsemcor-standalone.xsd").readlines()))))
            xmlschema.assertValid(self.tree)
187054
public function validate( $xml )
	{
		$parser	= xml_parser_create();
		$dummy	= create_function( '', '' );
		xml_set_element_handler( $parser, $dummy, $dummy );
		xml_set_character_data_handler( $parser, $dummy );
		if( !xml_parse( $parser, $xml ) )
		{
			$msg	= "%s at line %d";
			$error	= xml_error_string( xml_get_error_code( $parser ) );
			$line	= xml_get_current_line_number( $parser );
			$this->error['message']	= sprintf( $msg, $error, $line );
			$this->error['line']	= $line;
			$this->error['xml']		= $xml;
			xml_parser_free( $parser );
			return FALSE;
		}
		xml_parser_free( $parser );
		return TRUE;
	}
424899
def validate(self, path):
        """"""
        # Exclude hidden files and folders with '.' prefix
        if os.path.basename(path).startswith('.'):
            return False

        # Check that current path level is more than min path and less than max path
        if not self.check_level(path):
            return False

        if self.filters:
            if not self._level_filters(path):
                return False

        # Force include and exclude iterations to be strings in case of integer filters
        # Handle exclusions
        if self.to_exclude:
            if any(str(ex).lower() in path.lower() for ex in self.to_exclude):
                return False

        # Handle inclusions
        if self.to_include:
            if not any(str(inc).lower() in path.lower() for inc in self.to_include):
                return False

        return True
836658
public XmlValidationResult validate(File xmlFile, EntityResolver entityResolver, XmlErrorHandlerAbstract errorHandler) {
    	if (xmlFile == null) {
    		throw new IllegalArgumentException("xmlFile is null");
    	}
        XmlValidationResult result = new XmlValidationResult();
        if (errorHandler == null) {
            errorHandler = new XmlErrorHandler();
        }
        errorHandler.reset();
        InputStream in = null;
        try {
            /*
             * Test for well-formed-ness.
             */
            in = new FileInputStream(xmlFile);
            if (builderParsing != null) {
                try {
                    builderParsing.reset();
                } catch (UnsupportedOperationException e) {
                	builderParsing = null;
                }
            }
            if (builderParsing == null) {
                try {
                    builderParsing = factoryParsing.newDocumentBuilder();
                } catch (ParserConfigurationException e) {
                    throw new IllegalStateException("Could not create a new 'DocumentBuilder'!");
                }
            }
            builderParsing.setErrorHandler(errorHandler);
            result.document = builderParsing.parse(in);
            in.close();
            in = null;
            result.bWellformed = !errorHandler.hasErrors();
            /*
             * Look for references to DTD or XSD.
             */
            DocumentType documentType = result.document.getDoctype();
            if (documentType != null) {
                result.systemId = documentType.getSystemId();
            }
            if (result.systemId != null) {
                result.bDtdUsed = true;
            } else {
                XPathFactory xpf = XPathFactory.newInstance();
                XPath xp = xpf.newXPath();
                NodeList nodes;
                Node node;
                // JDK6 XPath engine supposedly only implements v1.0 of the specs.
                nodes = (NodeList)xp.evaluate("//*", result.document.getDocumentElement(), XPathConstants.NODESET);
                for (int i = 0; i < nodes.getLength(); i++) {
                    node = nodes.item(i).getAttributes().getNamedItem("xmlns:xsi");
                    if (node != null) {
                        result.xsiNamespaces.add(node.getNodeValue());
                        result.bXsdUsed = true;
                    }
                    node = nodes.item(i).getAttributes().getNamedItem("xsi:schemaLocation");
                    if (node != null) {
                        // debug
                        result.schemas.add(node.getNodeValue());
                        result.bXsdUsed = true;
                    }
                }
            }
            /*
             * Validate against DTD/XSD.
             */
            if (result.bDtdUsed || result.bXsdUsed) {
                in = new FileInputStream(xmlFile);
                if (builderValidating != null) {
                    try {
                        builderValidating.reset();
                    } catch (UnsupportedOperationException e) {
                    	builderValidating = null;
                    }
                }
                if (builderValidating == null) {
                    try {
                        builderValidating = factoryValidating.newDocumentBuilder();
                    } catch (ParserConfigurationException e) {
                        throw new IllegalStateException("Could not create a new 'DocumentBuilder'!");
                    }
                }
                builderValidating.setEntityResolver(entityResolver);
                builderValidating.setErrorHandler(errorHandler);
                result.document = builderValidating.parse(in);
                in.close();
                in = null;
                result.bValid = !errorHandler.hasErrors();
            }
        } catch (Throwable t) {
            logger.error("Exception validating XML stream!", t.toString(), t);
            try {
                String publicId = "";
                String systemId = "";
                int lineNumber = -1;
                int columnNumber = -1;
                Exception sillyApiException = new Exception("XML validation exception!", t);
                errorHandler.error(new SAXParseException(t.toString(), publicId, systemId, lineNumber, columnNumber, sillyApiException));
            } catch (SAXException e) {
                throw new IllegalStateException("Failed to add error to ErrorHandler!", e);
            }
            result.bWellformed = false;
            result.bValid = false;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    logger.error("Exception closing stream!", e.toString(), e);
                }
                in = null;
            }
        }
        return result;
    }
909699
public void validate(final Node document) throws SchemaValidationException
	{
		try
		{
			final Validator validator = schema.newValidator();

			validator.validate(new DOMSource(document));
		}
		catch (SAXException | IOException e)
		{
			throw new SchemaValidationException(e.getMessage(), e);
		}
	}
1290931
def validate()
       failed = []
        
        @loaded_schema['sections'].each{
          |section|
          
          #check required sections are there
          if (section['required'] && !@loaded_file.has_key?(section['name']))
            @errors.push('Error: missing required section - ' + section['name'])
            failed.push(section['name'])
          elsif @loaded_file.has_key?(section['name'])
            node = @loaded_file[section['name']]
            validated = match_node(node,section,section['name'])
            if(!validated)
              failed.push(section['name'])
            end
          end
               
        }
        
        result = {}       
        result["result"] = failed.empty?
        
        if !failed.empty? && !@errors.empty?
          result["errors"] = @errors
        end
        
        return result
      end
950068
public void validateXMLString(String xml, String dtdFile, String docType) throws SAXException, IOException, ParserConfigurationException {
    validateInternal(xml, dtdFile, docType);
  }
340859
def validate(self, ymldata=None, messages=None):
        """"""
        schema_val = self.schema_val(messages)
        if len(messages) == 0:
            content_val = self.content_val(ymldata, messages)

        return schema_val and content_val
851099
def validate_file(parser, arg):
    """"""
    if not os.path.isfile(arg):
        parser.error("%s is not a file." % arg)
    return arg
1106652
function validate(doc, schema, prefix, options) {
  schema.validate(doc, prefix, options);
}