TriX serializer places two xmlns attributes on same element · Issue #250 · RDFLib/rdflib (original) (raw)

When I have a ConjunctiveGraph with the default namespace set, for example

>>> import rdflib
>>> g = rdflib.ConjunctiveGraph()
>>> g.bind(None, "http://defaultnamespace")

then the Trix serializer binds the default namespace twice in its XML output, once for the Trix namespace and once for the namespace I used:

>>> print(g.serialize(format='trix').decode('UTF-8'))
<?xml version="1.0" encoding="utf-8"?>
<TriX
  xmlns:xml="http://www.w3.org/XML/1998/namespace"
  xmlns="http://defaultnamespace"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns="http://www.w3.org/2004/03/trix/trix-1/"
/>

I don't know how one should fix this. The problem is with the function TriXSerializer.serialize or the function XMLWriter.namespaces. TriXSerializer.serialize could remove the namespace with the empty prefix or XMLWriter.namespaces could give precedence to the namespaces in extra_ns over those in namespace.