我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用xml.dom.XML_NAMESPACE。
def parseTerm(element): """rdflib object (Literal, URIRef, BNode) for the given elementtree element""" tag, text = element.tag, element.text if tag == RESULTS_NS_ET + 'literal': if text is None: text = '' datatype = None lang = None if element.get('datatype', None): datatype = URIRef(element.get('datatype')) elif element.get("{%s}lang" % XML_NAMESPACE, None): lang = element.get("{%s}lang" % XML_NAMESPACE) ret = Literal(text, datatype=datatype, lang=lang) return ret elif tag == RESULTS_NS_ET + 'uri': return URIRef(text) elif tag == RESULTS_NS_ET + 'bnode': return BNode(text) else: raise TypeError("unknown binding type %r" % element)
def __init__(self, documentFactory=None): from xml.dom import XML_NAMESPACE self.documentFactory = documentFactory self.firstEvent = [None, None] self.lastEvent = self.firstEvent self.elementStack = [] self.push = self.elementStack.append try: self.pop = self.elementStack.pop except AttributeError: # use class' pop instead pass self._ns_contexts = [{XML_NAMESPACE:'xml'}] # contains uri -> prefix dicts self._current_context = self._ns_contexts[-1] self.pending_events = []
def __init__(self, output, encoding='utf-8'): writer = XMLGenerator(output, encoding) writer.startDocument() writer.startPrefixMapping(u'sparql', SPARQL_XML_NAMESPACE) writer.startPrefixMapping(u'xml', XML_NAMESPACE) writer.startElementNS( (SPARQL_XML_NAMESPACE, u'sparql'), u'sparql', AttributesNSImpl({}, {})) self.writer = writer self._output = output self._encoding = encoding self._results = False
def write_binding(self, name, val): assert self._resultStarted attr_vals = { (None, u'name'): unicode(name), } attr_qnames = { (None, u'name'): u'name', } self.writer.startElementNS( (SPARQL_XML_NAMESPACE, u'binding'), u'binding', AttributesNSImpl(attr_vals, attr_qnames)) if isinstance(val, URIRef): self.writer.startElementNS( (SPARQL_XML_NAMESPACE, u'uri'), u'uri', AttributesNSImpl({}, {})) self.writer.characters(val) self.writer.endElementNS( (SPARQL_XML_NAMESPACE, u'uri'), u'uri') elif isinstance(val, BNode): self.writer.startElementNS( (SPARQL_XML_NAMESPACE, u'bnode'), u'bnode', AttributesNSImpl({}, {})) self.writer.characters(val) self.writer.endElementNS( (SPARQL_XML_NAMESPACE, u'bnode'), u'bnode') elif isinstance(val, Literal): attr_vals = {} attr_qnames = {} if val.language: attr_vals[(XML_NAMESPACE, u'lang')] = val.language attr_qnames[(XML_NAMESPACE, u'lang')] = u"xml:lang" elif val.datatype: attr_vals[(None, u'datatype')] = val.datatype attr_qnames[(None, u'datatype')] = u'datatype' self.writer.startElementNS( (SPARQL_XML_NAMESPACE, u'literal'), u'literal', AttributesNSImpl(attr_vals, attr_qnames)) self.writer.characters(val) self.writer.endElementNS( (SPARQL_XML_NAMESPACE, u'literal'), u'literal') else: raise Exception("Unsupported RDF term: %s" % val) self.writer.endElementNS( (SPARQL_XML_NAMESPACE, u'binding'), u'binding')