def validateMiniXsv(xml_fn, xsd_fn): try: from minixsv import pyxsval pyxsval.parseAndValidate(xml_fn, xsd_fn) except ImportError: log.debug("minixsv not found, validation disabled")
def ValidateInput(schemaPath): ''' Validate input XML file to check if it matches the specified schema. ''' global opts print('Validating XML...') for xmlFile in opts.xmlDef: pyxsval.parseAndValidate(xmlFile, xsdFile=opts.schema)
def ValidateInput(schemaPath): ''' Validate input XML file to check if it matches the specified schema. ''' global opts print('Validating XML...') for xmlFile in opts.xmlDef: pyxsval.parseAndValidate(xmlFile, xsdFile = opts.schema)
def __init__(self, interface_file): """ Validate and read XML. Private constructor. Should not be used directly, but rather through XMLGroupReader.get_instance """ self.logger = get_logger(self.__class__.__module__ + '.') self.logger.debug("Starting to validate XML file " + interface_file) try: pyxsval.parseAndValidate(interface_file) except pyxsval.XsvalError, errstr: msg = "The XML file " + str(interface_file) + " is not valid. " self.logger.error(msg + "Error message: " + str(errstr)) raise XmlParserException(msg + "Error message: " + str(errstr))
def mavgen_validate(fname, schema, errorLimitNumber) : """Uses minixsv to validate an XML file with a given XSD schema file.""" # use default values of minixsv, location of the schema file must be specified in the XML file domTreeWrapper = pyxsval.parseAndValidate(fname, xsdFile=schema, errorLimit=errorLimitNumber) # domTree is a minidom document object domTree = domTreeWrapper.getTree()
def validate(file_in): """ Function expects a file as a parameter. Checks if file is a valid xml file. Returns False if not, and an element tree built from the file if it is valid. @type file_in: File @param file_in: file uploaded by the user, passed by views.py @rtype: Boolean or ElementTree @return: Returns False if the filen is invalid XML, or an element tree built from the file if it is valid. """ name = str(file_in.name) if name[-4:] != ".xml" and name[-4:] != ".XML": return False xsd = open('wcdb/WorldCrises.xsd.xml', 'r') xmlFile = open('wcdb/temp.xml', 'w') xmlFile.write(file_in.read()) xmlFile = open('wcdb/temp.xml', 'r') try: psvi = pyxsval.parseAndValidate("wcdb/temp.xml", "wcdb/WorldCrises.xsd.xml", xmlIfClass=pyxsval.XMLIF_ELEMENTTREE) tree = psvi.getTree() except pyxsval.XsvalError, e: return 'Validation aborted. ' + str(e)
def __loadAndValidate(self, xml, xsd, xmlHash, xsdHash): try: # Validate the config file pyxsval.parseAndValidate( inputFile=xml, xsdFile=xsd, **Objectify.KWARGS) except Exception: raise Exception(format_exc()) #gnosis.xml.objectify._XO_node = Node.Node #gnosis.xml.objectify._XO_interface = Interface.Interface self.configuration = make_instance(xml) hashPath = self.__getXmlHashFile(xml) try: with open(hashPath, 'w') as hashFile: hashFile.write("%s\n%s" % (xmlHash, xsdHash)) hashFile.close() except IOError, e: self.logger.error(e)
def importXMLToDjango(xmlFilename): #password = raw_input("Password: "******"gummy"): # print "Bad password!" # exit(1) #xmlFilename = raw_input("Filename of the XML file: ") #schemaFilename = raw_input("Filename of the schema file: ") # xmlFilename = "static/hc7795-WCDB2.xml" schemaFilename = "static/WorldCrises.xsd.xml" # Validate the XML file. try: # call validator with non-default values elementTreeWrapper = pyxsval.parseAndValidate (xmlFilename, xsdFile = schemaFilename, xmlIfClass = pyxsval.XMLIF_ELEMENTTREE, warningProc = pyxsval.PRINT_WARNINGS, errorLimit = 200, verbose = 1, useCaching = 0, processXInclude = 0) # get elementtree object after validation xmlTree = elementTreeWrapper.getTree() except pyxsval.XsvalError as errstr: print errstr print "Validation aborted!" raise pyxsval.XsvalError except GenXmlIfError as errstr: print errstr print "Parsing aborted!" raise GenXmlIfError Common.objects.all().delete() List.objects.all().delete() # Get a list of model objects from xmlTree. modelsList = elementTreeToModels(xmlTree) # Put the models in the Django database. importXML(modelsList)
def read_and_validate_xml (filename) : """ Reads and validates the XML file specified by filename Uses minixsv and genxmlif libraries Throws exceptions if the validation fails """ try : elementTreeWrapper = pyxsval.parseAndValidate (filename, xsdFile=xsd_filename, xmlIfClass=pyxsval.XMLIF_ELEMENTTREE, warningProc=pyxsval.PRINT_WARNINGS, errorLimit=200, verbose=0, useCaching=0, processXInclude=0 ) elemTree = elementTreeWrapper.getTree() return elemTree.getroot() except pyxsval.XsvalError, errstr : raise Exception ('Could not validate XML files ' + xsd_filename + ' and/or ' + xsd_filename, errstr)
def validate(file_in) : """ Function expects a file as a parameter. Checks if file is a valid xml file. Returns False if not, and an element tree built from the file if it is valid. @type file_in: File @param file_in: file uploaded by the user, passed by views.py @rtype: Boolean or ElementTree @return: Returns False if the filen is invalid XML, or an element tree built from the file if it is valid. """ name = str(file_in.name) if name[-4:] != ".xml" and name[-4:] != ".XML" : return False xsd = open('wcdb/WorldCrises.xsd.xml', 'r') xmlFile = open('wcdb/temp.xml', 'w') xmlFile.write(file_in.read()) xmlFile = open('wcdb/temp.xml', 'r') try: psvi = pyxsval.parseAndValidate("wcdb/temp.xml", "wcdb/WorldCrises.xsd.xml", xmlIfClass=pyxsval.XMLIF_ELEMENTTREE) tree = psvi.getTree() except pyxsval.XsvalError, e: return 'Validation aborted. ' + str(e)
from minixsv import pyxsval print pyxsval.parseAndValidate('../../xml_files/test/xxe.xml')
def validate(xml, xsd): try: parseAndValidate(xml, xsdFile=xsd) except IOError, errstr: return ValidationResult(False, errstr)
def validateMiniXsv(xml_fn, xsd_fn): try: from minixsv import pyxsval pyxsval.parseAndValidate(xml_fn, xsd_fn) except ImportError: log.debug('minixsv not found, validation disabled')
def __init__(self, filenameXML, filenameXSD): self.fileout = filenameXML self.doc = pyxsval.parseAndValidate(filenameXML, filenameXSD) self.tree = self.doc.getTree() self.regs = self.tree.document.getElementsByTagName('Registro')