diff -r adda406d3960 -r 13ee5f4ab612 xmlclass/xsdschema.py --- a/xmlclass/xsdschema.py Wed Aug 07 11:47:14 2013 +0200 +++ b/xmlclass/xsdschema.py Mon Aug 26 10:55:03 2013 +0200 @@ -939,8 +939,9 @@ factory.BlockDefault = attributes["blockDefault"] factory.FinalDefault = attributes["finalDefault"] - if attributes.has_key("targetNamespace"): - factory.TargetNamespace = factory.DefinedNamespaces.get(attributes["targetNamespace"], None) + factory.TargetNamespace = factory.DefinedNamespaces.get(attributes["targetNamespace"], None) + if factory.TargetNamespace is not None: + factory.etreeNamespaceFormat = "{%s}%%s" % attributes["targetNamespace"] factory.Namespaces[factory.TargetNamespace] = {} annotations, children = factory.ReduceElements(elements, True) @@ -1030,15 +1031,14 @@ schema = child break for qualified_name, attr in schema._attrs.items(): - value = GetAttributeValue(attr) - if value == "http://www.w3.org/2001/XMLSchema": - namespace, name = DecomposeQualifiedName(qualified_name) - if namespace == "xmlns": - self.DefinedNamespaces["http://www.w3.org/2001/XMLSchema"] = name + namespace, name = DecomposeQualifiedName(qualified_name) + if namespace == "xmlns": + value = GetAttributeValue(attr) + self.DefinedNamespaces[value] = name + self.NSMAP[name] = value + if value == "http://www.w3.org/2001/XMLSchema": self.SchemaNamespace = name - else: - self.DefinedNamespaces["http://www.w3.org/2001/XMLSchema"] = self.SchemaNamespace - self.Namespaces[self.SchemaNamespace] = XSD_NAMESPACE + self.Namespaces[self.SchemaNamespace] = XSD_NAMESPACE self.Schema = XSD_NAMESPACE["schema"]["extract"]["default"](self, schema) ReduceSchema(self, self.Schema[1], self.Schema[2]) @@ -1084,19 +1084,20 @@ return None """ -This function opens the xsd file and generate the classes from the xml tree +This function opens the xsd file and generate a xml parser with class lookup from +the xml tree """ -def GenerateClassesFromXSD(filepath): +def GenerateParserFromXSD(filepath): xsdfile = open(filepath, 'r') - factory = XSDClassFactory(minidom.parse(xsdfile), filepath) + xsdstring = xsdfile.read() xsdfile.close() - return GenerateClasses(factory) + return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring), filepath), xsdstring) """ -This function generate the classes from the xsd given as a string +This function generate a xml from the xsd given as a string """ -def GenerateClassesFromXSDstring(xsdstring): - return GenerateClasses(XSDClassFactory(minidom.parseString(xsdstring))) +def GenerateParserFromXSDstring(xsdstring): + return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring))) #-------------------------------------------------------------------------------