or about with...">

RDF/XML behaves weird if RDF is the default namespace · Issue #468 · RDFLib/rdflib (original) (raw)

Noticed this while trying to parse mozilla addon install.rdf files. They use xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" so they don't have to prefix things like <Description> or about with <rdf:Description> or rdf:about.

Parsing such a file the current rdflib will not understand the rdf basics anymore and introduce BNodes to capture the xml.

Examples:

Here we define the rdf namespace as commonly done:

In [64]: my_data = ''' <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'

<rdf:Description rdf:about="urn:mozilla:install-manifest"> rdfs:labelExample rdfs:commentThis is really just an example. '''

In [65]: g = rdflib.Graph()

In [66]: g.parse(data=my_data) Out[66]: <Graph identifier=N84e0685a0c7c4dd2be6a59ad9cbadac9 (<class 'rdflib.graph.Graph'>)>

In [67]: list(g) Out[67]: [(rdflib.term.URIRef(u'urn:mozilla:install-manifest'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal(u'Example')), (rdflib.term.URIRef(u'urn:mozilla:install-manifest'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#comment'), rdflib.term.Literal(u'This is really just an example.'))]

this is ok.

let's use something other than rdf, e.g. fdr:

In [76]: my_data = ''' ....: <fdr:RDF ....: xmlns:fdr='http://www.w3.org/1999/02/22-rdf-syntax-ns#' ....: xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#' ....: > ....: <fdr:Description fdr:about="urn:mozilla:install-manifest"> ....: rdfs:labelExample ....: rdfs:commentThis is really just an example. ....: ....: ....: '''

In [77]: g = rdflib.Graph()

In [78]: g.parse(data=my_data) Out[78]: <Graph identifier=N877052e9ac414a52841a8157ab590fb2 (<class 'rdflib.graph.Graph'>)>

In [79]: list(g) Out[79]: [(rdflib.term.URIRef(u'urn:mozilla:install-manifest'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal(u'Example')), (rdflib.term.URIRef(u'urn:mozilla:install-manifest'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#comment'), rdflib.term.Literal(u'This is really just an example.'))]

this looks ok as well.

now let's make rdf the default namespace so we don't need to prefix everything with rdf (2nd line):

In [68]: my_data = ''' <RDF xmlns='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:rdfs='http://www.w3.org/2000/01/rdf-schema#'

Example This is really just an example. '''

In [69]: g = rdflib.Graph()

In [70]: g.parse(data=my_data) Out[70]: <Graph identifier=Nc29cd64640354624874a897aea509b12 (<class 'rdflib.graph.Graph'>)>

In [71]: list(g) Out[71]: [(rdflib.term.BNode('N6da6e3fa36bc4a898e3ef99e67e29cc7'), rdflib.term.URIRef(u'about'), rdflib.term.Literal(u'urn:mozilla:install-manifest')), (rdflib.term.BNode('N6da6e3fa36bc4a898e3ef99e67e29cc7'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal(u'Example')), (rdflib.term.BNode('N6da6e3fa36bc4a898e3ef99e67e29cc7'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#comment'), rdflib.term.Literal(u'This is really just an example.'))]

this looks as if rdflib doesn't understand rdf anymore, as it introduces a BNode above all :(