Loading 103120/examples/FooServiceSchema.xsd 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://FooServiceSchema.example.com/schema/v1.1.1/" elementFormDefault="qualified" xmlns="http://FooServiceSchema.example.com/schema/v1.1.1/" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="FooItem" type="FooItem"></xs:element> <xs:complexType name="FooItem"> <xs:sequence> <xs:element name="item1" type="ItemType"></xs:element> <xs:element name="item2" type="ItemType"></xs:element> <xs:element name="item3" type="ItemType"></xs:element> </xs:sequence> </xs:complexType> <xs:simpleType name="ItemType"> <xs:restriction base="xs:string"> <xs:enumeration value="Foo"></xs:enumeration> <xs:enumeration value="Bar"></xs:enumeration> <xs:enumeration value="Baz"></xs:enumeration> </xs:restriction> </xs:simpleType> </xs:schema> testing/check_xsd.py +20 −5 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbosity", help="verbosity level", action="count", default=0) parser.add_argument("input", help="include a directory or file", action="append", nargs="+") parser.add_argument("-p", "--primaryNamespace", help="Primary schema namespace for instance doc validation") args = parser.parse_args() logging.getLogger().setLevel(logging.WARNING) Loading @@ -101,6 +102,7 @@ if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) logging.debug("Very verbose selected") logging.debug(f"Path: {args.input}") includeFileList = [] includeInstanceDocList = [] Loading @@ -118,14 +120,18 @@ if __name__ == '__main__': logging.info(f">Including instance doc {g}") includeInstanceDocList.append(g) else: logging.info(f"Including {p.absolute()}") logging.info(f">Including {p.absolute()}") if str(p.absolute()).endswith('.xml'): includeInstanceDocList.append(p.absolute()) elif str(p.absolute()).endswith('.xml'): includeFileList.append(p.absolute()) includeInstanceDocList.append(str(p.absolute())) elif str(p.absolute()).endswith('.xsd'): includeFileList.append(str(p.absolute())) else: logging.warning(f'Ignoring file {p.absolute()}') if len(includeInstanceDocList) and (args.primaryNamespace is None): print("Cannot validate instance documents without specifying a primary namespace (use -h for usage guidelines)") exit(-1) syntaxErrors = 0 print ("XSD syntax checks:") Loading Loading @@ -169,6 +175,15 @@ if __name__ == '__main__': print ("-----------------------------") errorCount = 0 primarySchema = schemaDict[args.primaryNamespace] for instanceDoc in includeInstanceDocList: print (f" {instanceDoc:}") try: results = primarySchema.validate(instanceDoc) print (f" {instanceDoc} : OK") except Exception as ex: errorCount += 1 print (f" {instanceDoc} : {str(ex)}") print (f"{errorCount} instance doc errors detected") exit(errorCount) Loading
103120/examples/FooServiceSchema.xsd 0 → 100644 +27 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://FooServiceSchema.example.com/schema/v1.1.1/" elementFormDefault="qualified" xmlns="http://FooServiceSchema.example.com/schema/v1.1.1/" xmlns:mstns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="FooItem" type="FooItem"></xs:element> <xs:complexType name="FooItem"> <xs:sequence> <xs:element name="item1" type="ItemType"></xs:element> <xs:element name="item2" type="ItemType"></xs:element> <xs:element name="item3" type="ItemType"></xs:element> </xs:sequence> </xs:complexType> <xs:simpleType name="ItemType"> <xs:restriction base="xs:string"> <xs:enumeration value="Foo"></xs:enumeration> <xs:enumeration value="Bar"></xs:enumeration> <xs:enumeration value="Baz"></xs:enumeration> </xs:restriction> </xs:simpleType> </xs:schema>
testing/check_xsd.py +20 −5 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbosity", help="verbosity level", action="count", default=0) parser.add_argument("input", help="include a directory or file", action="append", nargs="+") parser.add_argument("-p", "--primaryNamespace", help="Primary schema namespace for instance doc validation") args = parser.parse_args() logging.getLogger().setLevel(logging.WARNING) Loading @@ -101,6 +102,7 @@ if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) logging.debug("Very verbose selected") logging.debug(f"Path: {args.input}") includeFileList = [] includeInstanceDocList = [] Loading @@ -118,14 +120,18 @@ if __name__ == '__main__': logging.info(f">Including instance doc {g}") includeInstanceDocList.append(g) else: logging.info(f"Including {p.absolute()}") logging.info(f">Including {p.absolute()}") if str(p.absolute()).endswith('.xml'): includeInstanceDocList.append(p.absolute()) elif str(p.absolute()).endswith('.xml'): includeFileList.append(p.absolute()) includeInstanceDocList.append(str(p.absolute())) elif str(p.absolute()).endswith('.xsd'): includeFileList.append(str(p.absolute())) else: logging.warning(f'Ignoring file {p.absolute()}') if len(includeInstanceDocList) and (args.primaryNamespace is None): print("Cannot validate instance documents without specifying a primary namespace (use -h for usage guidelines)") exit(-1) syntaxErrors = 0 print ("XSD syntax checks:") Loading Loading @@ -169,6 +175,15 @@ if __name__ == '__main__': print ("-----------------------------") errorCount = 0 primarySchema = schemaDict[args.primaryNamespace] for instanceDoc in includeInstanceDocList: print (f" {instanceDoc:}") try: results = primarySchema.validate(instanceDoc) print (f" {instanceDoc} : OK") except Exception as ex: errorCount += 1 print (f" {instanceDoc} : {str(ex)}") print (f"{errorCount} instance doc errors detected") exit(errorCount)