I am trying to load and parse a very simple rdf file in xml format using rdflib. I don't think, it is parsing correctly. Here is my rdf/xml file,
<rdf:RDF xmlns:rdf="http://w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
>
<foaf:Person>
<foaf:name>Peter Parker</foaf:name>
</foaf:Person>
</rdf:RDF>
My python script is here,
from rdflib import Graph
g = Graph()
g.parse("person_1.rdf", format="xml")
print(len(g))
print(g.serialize(format="xml").decode("u8"))
print("Test - 2")
And, here is the program output,
3
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>
<rdf:Description rdf:nodeID="Nababb97ad88341329a7cf22cec65c00c">
<rdf:type rdf:resource="http://w3.org/1999/02/22-rdf-syntax-ns#RDF"/>
<foaf:Person rdf:nodeID="Nfa7b9ab24fae4bcd9ffbaa13aeb733db"/>
</rdf:Description>
<rdf:Description rdf:nodeID="Nfa7b9ab24fae4bcd9ffbaa13aeb733db">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/name"/>
</rdf:Description>
</rdf:RDF>
Test - 2
I don't see the name "Peter Parker" in the output. Am I doing something wrong. Thanks in advance.
If you just want to retrieve the data, try the following method.
Result: