equal
deleted
inserted
replaced
937 factory.AttributeFormDefault = attributes["attributeFormDefault"] |
937 factory.AttributeFormDefault = attributes["attributeFormDefault"] |
938 factory.ElementFormDefault = attributes["elementFormDefault"] |
938 factory.ElementFormDefault = attributes["elementFormDefault"] |
939 factory.BlockDefault = attributes["blockDefault"] |
939 factory.BlockDefault = attributes["blockDefault"] |
940 factory.FinalDefault = attributes["finalDefault"] |
940 factory.FinalDefault = attributes["finalDefault"] |
941 |
941 |
942 factory.TargetNamespace = factory.DefinedNamespaces.get(attributes["targetNamespace"], None) |
942 targetNamespace = attributes.get("targetNamespace", None) |
|
943 factory.TargetNamespace = factory.DefinedNamespaces.get(targetNamespace, None) |
943 if factory.TargetNamespace is not None: |
944 if factory.TargetNamespace is not None: |
944 factory.etreeNamespaceFormat = "{%s}%%s" % attributes["targetNamespace"] |
945 factory.etreeNamespaceFormat = "{%s}%%s" % targetNamespace |
945 factory.Namespaces[factory.TargetNamespace] = {} |
946 factory.Namespaces[factory.TargetNamespace] = {} |
946 |
947 |
947 annotations, children = factory.ReduceElements(elements, True) |
948 annotations, children = factory.ReduceElements(elements, True) |
948 |
949 |
949 for child in children: |
950 for child in children: |
1095 |
1096 |
1096 """ |
1097 """ |
1097 This function generate a xml from the xsd given as a string |
1098 This function generate a xml from the xsd given as a string |
1098 """ |
1099 """ |
1099 def GenerateParserFromXSDstring(xsdstring): |
1100 def GenerateParserFromXSDstring(xsdstring): |
1100 return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring))) |
1101 return GenerateParser(XSDClassFactory(minidom.parseString(xsdstring)), xsdstring) |
1101 |
1102 |
1102 |
1103 |
1103 #------------------------------------------------------------------------------- |
1104 #------------------------------------------------------------------------------- |
1104 # XSD schema syntax elements |
1105 # XSD schema syntax elements |
1105 #------------------------------------------------------------------------------- |
1106 #------------------------------------------------------------------------------- |
2519 |
2520 |
2520 # Complex Types |
2521 # Complex Types |
2521 "anyType": {"type": COMPLEXTYPE, "extract": lambda x:None}, |
2522 "anyType": {"type": COMPLEXTYPE, "extract": lambda x:None}, |
2522 } |
2523 } |
2523 |
2524 |
2524 if __name__ == '__main__': |
|
2525 classes = GenerateClassesFromXSD("test.xsd") |
|
2526 |
|
2527 # Code for test of test.xsd |
|
2528 xmlfile = open("po.xml", 'r') |
|
2529 tree = minidom.parse(xmlfile) |
|
2530 xmlfile.close() |
|
2531 test = classes["PurchaseOrderType"]() |
|
2532 for child in tree.childNodes: |
|
2533 if child.nodeType == tree.ELEMENT_NODE and child.nodeName == "purchaseOrder": |
|
2534 test.loadXMLTree(child) |
|
2535 test.items.item[0].setquantity(2) |
|
2536 testfile = open("test.xml", 'w') |
|
2537 testfile.write(u'<?xml version=\"1.0\"?>\n') |
|
2538 testfile.write(test.generateXMLText("purchaseOrder").encode("utf-8")) |
|
2539 testfile.close() |
|