+ def _httpGetXSD(self, xsdURI):
+ # split the URI into relevant parts
+ host = xsdURI.split("/")[2]
+ if xsdURI.startswith("https"):
+ conn = httplib.HTTPSConnection(host,
+ httplib.HTTPSConnection.default_port)
+ elif xsdURI.startswith("http"):
+ conn = httplib.HTTPConnection(host,
+ httplib.HTTPConnection.default_port)
+ conn.request("GET", xsdURI)
+ # If we can't download the schema, raise an exception
+ r1 = conn.getresponse()
+ if r1.status != 200:
+ raise Exception
+ return r1.read().replace('\n', '').replace('\t', '').strip()
+
+
+ def _parseXSD(self, xsdURI):
+ """
+ Download XSD from URL, or if file, read local xsd file and set schemaDict
+ """
+ # Since the schema definiton is a global namespace shared by and agreed upon by
+ # others, this should probably be a URL. Check for URL, download xsd, parse, or
+ # if local file, use local file.
+ schemaDom = None
+ if xsdURI.startswith("http"):
+ try:
+ schemaDom = minidom.parseString(self._httpGetXSD(xsdURI))
+ except Exception, e:
+ # logging.debug("%s: web file not found" % xsdURI)
+ # logging.debug("Using local file %s" % self.xsd")
+ print e
+ print "Can't find %s on the web. Continuing." % xsdURI
+ if not schemaDom:
+ if os.path.exists(xsdURI):
+ # logging.debug("using local copy.")
+ print "Using local %s" % xsdURI
+ schemaDom = minidom.parse(xsdURI)
+ else:
+ raise Exception("Can't find xsd locally")
+ self.schemaDict = self.toDict(schemaDom.childNodes[0])
+
+