这是indexloc提供的服务,不要输入任何密码
Skip to content

Literal breaks canonical XML #3279

@namedgraph

Description

@namedgraph

I'm trying to serialize XMLLiterals with canonical XML using rdflib and encountered this unhelpful code:
https://github.com/RDFLib/rdflib/blob/main/rdflib/term.py#L1784

Can we just remove any "normalization" and let the user take care of that?

Code to reproduce:

from rdflib import Graph, Literal, URIRef
from rdflib.namespace import RDF

# C14N XML with explicit closing tag (correct)
xml_input = '<div xmlns="http://www.w3.org/1999/xhtml" class="test"></div>'
print(f"Input XML: {xml_input}")

# Create XMLLiteral
g = Graph()
g.add((URIRef("http://test"), RDF.value, Literal(xml_input, datatype=RDF.XMLLiteral)))

# Serialize to N-Triples
nt = g.serialize(format='nt')
print(f"\nN-Triples output:")
print(nt)

Output:

Input XML: <div xmlns="http://www.w3.org/1999/xhtml" class="test"></div>

N-Triples output:
<http://test> <http://www.w3.org/1999/02/22-rdf-syntax-ns#value> "<div xmlns=\"http://www.w3.org/1999/xhtml\" class=\"test\"/>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral> .

In c14n XML there are no self-closing tags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions