Skip to content

Pretty RDF/XML serializer misses core namespaces #2408

@kouralex

Description

@kouralex

Whilst the following works as expected

from rdflib import Graph
g = Graph(bind_namespaces='none').parse(data='prefix ex: <http://example.org/> ex:a ex:b "test"@en .')
g.print(format="xml")

output:

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF
   xmlns:ex="http://example.org/"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
  <rdf:Description rdf:about="http://example.org/a">
    <ex:b xml:lang="en">test</ex:b>
  </rdf:Description>
</rdf:RDF>

the following one does not (due to ns1: and ns2:):

from rdflib import Graph
g = Graph(bind_namespaces='none').parse(data='prefix ex: <http://example.org/> ex:a ex:b "test"@en .')
g.print(format="pretty-xml")

output:

<?xml version="1.0" encoding="utf-8"?>
<ns1:RDF
  xmlns:ex="http://example.org/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
  <ns1:Description ns1:about="http://example.org/a">
    <ex:b ns2:lang="en">test</ex:b>
  </ns1:Description>
</ns1:RDF>

It seems like the culprit is in how the namespaces are registered in case bind_namepaces='none' is set, as removing it makes both of them work identically.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions