#NEWLINE# def validate( modelDocument , schemaElement , targetNamespace ) : #NEWLINE# #INDENT# modelXbrl = modelDocument . modelXbrl #NEWLINE# modelManager = modelXbrl . modelManager #NEWLINE# '\n    if not hasattr(modelManager, "xmlSchemaSchema"):\n        if getattr(modelManager, "modelXmlSchemaIsLoading", False):\n            return\n        startedAt = time.time()\n        modelManager.modelXmlSchemaIsLoading = True\n        priorValidateDisclosureSystem = modelManager.validateDisclosureSystem\n        modelManager.validateDisclosureSystem = False\n        modelManager.xmlSchemaSchema = ModelXbrl.load(modelManager, XMLSchemaURI, _("validate schema"))\n        modelManager.validateDisclosureSystem = priorValidateDisclosureSystem\n        \'\'\'\n        filePath = modelManager.cntlr.webCache.getfilename(XMLSchemaURI)\n        modelManager.showStatus(_("lxml compiling XML Schema for Schemas"))\n        modelManager.xmlSchemaSchema = etree.XMLSchema(file=filePath)\n        \'\'\'\n        modelXbrl.info("info:xmlSchemaValidator", format_string(modelXbrl.modelManager.locale, \n                                            _("schema for XML schemas loaded into lxml %.3f secs"), \n                                            time.time() - startedAt),\n                                            modelDocument=XMLSchemaURI)\n        modelManager.showStatus("")\n        del modelManager.modelXmlSchemaIsLoading\n    \'\'\'\n    #startedAt = time.time()\n    #validationSuccess = modelManager.xmlSchemaSchema.validate(schemaElement)\n    #modelXbrl.info("info:xmlSchemaValidator", format_string(modelXbrl.modelManager.locale, \n    #                                    _("schema validated in %.3f secs"), \n    #                                    time.time() - startedAt),\n    #                                    modelDocument=modelDocument)\n    if not validationSuccess:\n        for error in modelManager.xmlSchemaSchema.error_log:\n            modelXbrl.error("xmlSchema:syntax",\n                    _("%(error)s, %(fileName)s, line %(line)s, column %(column)s, %(sourceAction)s source element"),\n                    modelObject=modelDocument, fileName=modelDocument.basename, \n                    error=error.message, line=error.line, column=error.column, sourceAction=("xml schema"))\n        modelManager.xmlSchemaSchema._clear_error_log()\n    \'\'\'\n    ' #NEWLINE# declaredNamespaces = set ( ( doc . targetNamespace for ( doc , docRef ) in modelDocument . referencesDocument . items ( ) if ( docRef . referenceType in ( 'include' , 'import' ) ) ) ) #NEWLINE# if targetNamespace : #NEWLINE# #INDENT# declaredNamespaces . add ( targetNamespace ) #NEWLINE# #UNINDENT# if ( targetNamespace in ( 'http://www.w3.org/2001/XMLSchema' , 'http://www.w3.org/XML/1998/namespace' ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# def resolvedQnames( elt , qnDefs ) : #NEWLINE# #INDENT# for ( attrName , attrType , mdlObjects , isQualifiedForm ) in qnDefs : #NEWLINE# #INDENT# attr = elt . get ( attrName ) #NEWLINE# if ( attr is not None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# qnValue = elt . schemaNameQname ( attr , isQualifiedForm = ( isQualifiedForm or elt . isQualifiedForm ) , prefixException = ValueError ) #NEWLINE# if ( qnValue . namespaceURI == XbrlConst . xsd ) : #NEWLINE# #INDENT# if ( attrType != ModelType ) : #NEWLINE# #INDENT# raise ValueError ( '{0} can not have xml schema namespace' . format ( attrName ) ) #NEWLINE# #UNINDENT# if ( qnValue . localName not in { 'anySimpleType' , 'anyType' , 'string' , 'boolean' , 'float' , 'double' , 'decimal' , 'duration' , 'dateTime' , 'time' , 'date' , 'gYearMonth' , 'gYear' , 'gMonthDay' , 'gDay' , 'gMonth' , 'hexBinary' , 'base64Binary' , 'anyURI' , 'QName' , 'NOTATION' , 'normalizedString' , 'token' , 'language' , 'IDREFS' , 'ENTITIES' , 'NMTOKEN' , 'NMTOKENS' , 'NCName' , 'ID' , 'IDREF' , 'integer' , 'nonPositiveInteger' , 'negativeInteger' , 'long' , 'int' , 'short' , 'byte' , 'nonNegativeInteger' , 'unsignedLong' , 'unsignedInt' , 'unsignedShort' , 'unsignedByte' , 'positiveInteger' } ) : #NEWLINE# #INDENT# raise ValueError ( '{0} qname {1} not recognized' . format ( attrName , attr ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( qnValue . namespaceURI and ( qnValue . namespaceURI not in declaredNamespaces ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Namespace is not defined by an import or include element' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( qnValue not in mdlObjects ) : #NEWLINE# #INDENT# raise ValueError ( '{0} is not defined' . format ( attrName ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not isinstance ( mdlObjects [ qnValue ] , attrType ) ) : #NEWLINE# #INDENT# raise ValueError ( '{0} not resolved to expected object type' . format ( attrName ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# except ValueError as err : #NEWLINE# #INDENT# modelXbrl . error ( 'xmlSchema:valueError' , _ ( 'Element attribute %(typeName)s value error: %(value)s, %(error)s' ) , modelObject = elt , typeName = attrName , value = attr , error = err ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# def checkSchemaElements( parentElement ) : #NEWLINE# #INDENT# for elt in parentElement . iterchildren ( ) : #NEWLINE# #INDENT# if ( isinstance ( elt , ModelObject ) and ( elt . namespaceURI == XbrlConst . xsd ) ) : #NEWLINE# #INDENT# ln = elt . localName #NEWLINE# if ( ln == 'element' ) : #NEWLINE# #INDENT# resolvedQnames ( elt , ( ( 'ref' , ModelConcept , modelXbrl . qnameConcepts , False ) , ( 'substitutionGroup' , ModelConcept , modelXbrl . qnameConcepts , True ) , ( 'type' , ModelType , modelXbrl . qnameTypes , True ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ln == 'attribute' ) : #NEWLINE# #INDENT# resolvedQnames ( elt , ( ( 'ref' , ModelAttribute , modelXbrl . qnameAttributes , False ) , ( 'type' , ModelType , modelXbrl . qnameTypes , True ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# checkSchemaElements ( elt ) #NEWLINE# #UNINDENT# #UNINDENT# checkSchemaElements ( schemaElement )