def test_iterparse_method_with_unicode(self): xsd_string = """ <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <\u0192-root><test></test></\u0192-root> </xs:schema> """ XSDTree.iterparse(xsd_string, ("end", ))
def test_iterparse_method_without_decoded_symbols(self): xsd_string = """ <xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'> <ƒ-root><test></test></ƒ-root> </xs:schema> """ with self.assertRaises(XMLError): XSDTree.iterparse(xsd_string, ("end", ))
def get_global_namespace(xsd_string): """ Get global namespace used in schema (defined by xmlns=<namespace>) Returns: """ # events to look for during iterparse events = "start", "start-ns" # Initialize global namespace global_namespace = None # iterate file namespaces for event, elem in XSDTree.iterparse(xsd_string, events): if event == "start-ns": if len(elem[0]) == 0: global_namespace = elem[1] elif event == "start": break return global_namespace
def get_namespaces(xsd_string): """Returns dict of prefix and namespaces Args: xsd_string: Returns: """ # events to look for during iterparse events = "start", "start-ns" # initialize namespaces dictionary namespaces = {'xml': xml_utils_constants.XML_NAMESPACE} # iterate file namespaces for event, elem in XSDTree.iterparse(xsd_string, events): if event == "start-ns": if len(elem[0]) > 0 and len(elem[1]) > 0: namespaces[elem[0]] = "%s" % elem[1] elif event == "start": break return namespaces
def test_iterparse_method_without_unicode(self): xsd_string = "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'><root><test></test></root></xs:schema>" XSDTree.iterparse(xsd_string, ('end', ))