Skip to content

Graph.serialize strips some prefixes when emitting RDF/XML, but not turtle #2364

@jclerman

Description

@jclerman

rdflib version 6.3.2 (latest)

This problem seems like it might be related to #1997, but is different inasmuch as it is affected by serialization step of a parsed graph, rather than the parsing step.

I have an RDF file (in RDF/XML format, and a *.owl filename extension in case that matters) with several prefixes defined at the beginning. All of the prefixes are preserved in the result of:

from rdflib import Graph

g = Graph().parse("myfile.owl")
list(g.namespaces)

If I serialize via `g.serialize(format="xml") then some of the prefixes are lost - it looks like any prefixes that aren't actually used in the input RDF are dropped, which is surprising (after parsing, does the Graph object retain that information?). The presence of the mapped namespaces in URIs used in the RDF does not seem to matter (i.e., those namespaces are found in some of the URIs in the content).

If I serialize via `g.serialize(format="turtle") then my original prefixes are preserved. Yay, but... eh?

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreRelates to core functionality of RDFLib, i.e. `rdflib.{graph,store,term}`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions