Question

I'am using .Net RDF library to make some sparql query on RDF files. but when I tried to load the RDF file to C# .Net RDFlibrary.

The error is:

Unable to Parse this RDF/XML since System.Xml was unable to parse the document, see Inner Exception for details

My RDF file:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rdf:RDF [<!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
<!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
<!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'>]>
<rdf:RDF xmlns:xsd="http://www.w3.org/2001/XMLSchema#" 
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:dnr="http://www.dotnetrdf.org/configuration#"
         xmlns:rdf="http://www.w3.org/XML/1998/namespace#"
         xml:base="http://www.example.org/">

  <rdf:Description rdf:about="Fadi">
    <ns0:eat xmlns:ns0="http://example.org/">Apple</ns0:eat>
    <xml:startTime>00:01:38</xml:startTime>
    <xml:endTime>00:01:39</xml:endTime>
  </rdf:Description>
</rdf:RDF>

and the statement to load:

Graph myGraph = new Graph();
FileLoader.Load(myGraph, "C:\\Users\\hasoOn\\Desktop\\tt.rdf");

Can anyone tell me what is wrong? - and why I get this error?

Was it helpful?

Solution

Did you actually look at the Inner Exception as the exception messages tells you to? That would contain the XmlException that was produced and would tell you exactly what is wrong with your RDF/XML including positional information i.e. where in the file the error is.

In your case your problem happens to be that you have defined the rdf namespace twice on the same element i.e. you have two xmlns:rdf attributes on your root rdf:RDF element which makes your XML illegal.

If you remove that then it will be valid XML however it will still fail to parse in dotNetRDF because you have used the properties xml:startTime and xml:endTime without defining the xml namespace. I guess dotNetRDF should probably allow those because xml: is implicitly defined in XML though using the xml namespace for anything other than XML syntax itself is generally a very bad idea and a symptom of bad data modeling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top