def visit_import(self, node, parent): """ <import id = ID namespace = anyURI schemaLocation = anyURI {any attributes with non-schema Namespace}...> Content: (annotation?) </import> """ if not node.get('schemaLocation'): raise NotImplementedError("schemaLocation is required") namespace = node.get('namespace') location = node.get('schemaLocation') # Resolve import if it is a file location = absolute_location(location, self.schema._location) schema = self.parser_context.schema_objects.get(location) if schema: logger.debug("Returning existing schema: %r", location) self.schema._imports[namespace] = schema return schema schema_node = load_external( location, self.schema._transport, self.parser_context) schema = self.schema.__class__( schema_node, self.schema._transport, location, self.parser_context) self.schema._imports[namespace] = schema return schema
def visit_import(self, node, parent): """ <import id = ID namespace = anyURI schemaLocation = anyURI {any attributes with non-schema Namespace}...> Content: (annotation?) </import> """ if not node.get('schemaLocation'): raise NotImplementedError("schemaLocation is required") namespace = node.get('namespace') location = node.get('schemaLocation') # Resolve import if it is a file location = absolute_location(location, self.schema._location) schema = self.parser_context.schema_objects.get(location) if schema: logger.debug("Returning existing schema: %r", location) self.schema._imports[namespace] = schema return schema schema_node = load_external(location, self.schema._transport, self.parser_context) schema = self.schema.__class__(schema_node, self.schema._transport, location, self.parser_context) self.schema._imports[namespace] = schema return schema
def _load_content(self, location): """Load the XML content from the given location and return an lxml.Element object. :param location: The URL of the document to load :type location: string """ if hasattr(location, 'read'): return parse_xml(location.read()) return load_external(location, self.transport, self.location)
def visit_import(self, node, parent, namespace=None): if not node.get('schemaLocation'): raise NotImplementedError("schemaLocation is required") namespace = 'intschema+%s' % node.get('namespace') location = node.get('schemaLocation') if location.startswith('intschema+'): schema_node = self.schema_references[namespace] return self.visit_schema(schema_node) schema_node = load_external(location, self.schema_references) return self.visit_schema(schema_node)
def visit_include(self, node, parent): """ <include id = ID schemaLocation = anyURI {any attributes with non-schema Namespace}...> Content: (annotation?) </include> """ if not node.get('schemaLocation'): raise NotImplementedError("schemaLocation is required") location = node.get('schemaLocation') schema_node = load_external( location, self.schema._transport, self.parser_context, base_url=self.schema._base_url) return self.visit_schema(schema_node)
def visit_import(self, node, parent): """ <import id = ID namespace = anyURI schemaLocation = anyURI {any attributes with non-schema Namespace}...> Content: (annotation?) </import> """ namespace = node.get('namespace') location = node.get('schemaLocation') # Use namespace as location if the schemaLocation is missing if not location: if namespace: location = namespace else: raise NotImplementedError("schemaLocation is required") # Resolve import if it is a file location = absolute_location(location, self.schema._base_url) schema = self.parser_context.schema_objects.get(location) if schema: logger.debug("Returning existing schema: %r", location) self.schema._imports[namespace] = schema return schema schema_node = load_external( location, self.schema._transport, self.parser_context) # If this schema location is 'internal' then retrieve the original # location since that is used as base url for sub include/imports if location in self.parser_context.schema_locations: base_url = self.parser_context.schema_locations[location] else: base_url = location schema = self.schema.__class__( schema_node, self.schema._transport, location, self.parser_context, base_url) self.schema._imports[namespace] = schema return schema
def _load_content(self, location): if hasattr(location, 'read'): return self._parse_content(location.read()) return load_external( location, self.transport, self._parser_context, self.location)
def _load_content(self, location): if hasattr(location, 'read'): return self._parse_content(location.read()) return load_external(location, self.transport, self._parser_context, self.location)