Commits

Yuji Hanamura committed 0f2e51d

The first commit.

  • Participants

Comments (0)

Files changed (1)

File xml_validator.py

+#-*- coding: utf-8 -*-
+
+import sys
+import os
+import win32com.client
+
+
+def usage():
+    print 'Usage: python %s SCHEMA_FILE XML_FILE' % sys.argv[0]
+
+
+def main():
+
+    if len(sys.argv) != 3:
+        usage()
+        sys.exit()
+
+    schema_file_name = sys.argv[1]
+    xml_file_name = sys.argv[2]
+
+    if not os.path.isfile(schema_file_name) or not os.path.isfile(xml_file_name):
+        usage()
+        sys.exit()
+
+    schema_chache = win32com.client.Dispatch('MSXML2.XMLSchemaCache.4.0')
+    schema_chache.add('', schema_file_name)
+
+    xml_doc = win32com.client.Dispatch('MSXML2.DOMDocument.4.0')
+    xml_doc.async = False
+    result = xml_doc.load(xml_file_name)
+
+    if not result:
+        print '%d : %s' % (xml_doc.parseError.line, xml_doc.parseError.reason)
+        sys.exit()
+
+    xml_doc.schemas = schema_chache
+    result = xml_doc.validate()
+
+    if result.errorCode != 0:
+        print '%d : %s' % (result.line, result.reason)
+    else:
+        print 'Validate OK!'
+
+
+if __name__ == '__main__':
+    main()
+