Open nicola opened 10 years ago
I dont think schema.org serves application/rdf+xml right now, so the XML parser cant get the RDF from that serialization
I am so sorry I meant: http://schema.rdfs.org/all.rdf (I just updated the example for clarity!).
I think they do, but it might be not the right format!
Thanks for the clarification.
It's been a while since I used RDF/XML. However unless I'm mistaken schema.rdfs.org ought to contain the namespace at the top, something like:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
However it validates both in rapper and the w3c validator
W3C validator:
http://www.w3.org/RDF/Validator/rdfval?URI=http%3A%2F%2Fschema.rdfs.org%2Fall.rdf+&PARSE=Parse+URI%3A+&TRIPLES_AND_GRAPH=PRINT_TRIPLES&FORMAT=PNG_EMBED
Rapper:
rapper -g http://schema.rdfs.org/all.rdf
So maybe somehow it knows that rdf links to "http://www.w3.org/1999/02/22-rdf-syntax-ns# ... I asked on #swig and the response was that the namespace should be included.
Hi, same problem here when trying to load a local RDF/XML file -- rapper parses it without complaints; @nicola did you solve the problem somehow?
var fetch = $rdf.fetcher(kb);
fetch.nowOrWhenFetched('file:foaf.rdf', undefined, function(ok, body, xhr) {
console.log(ok);
console.log(body);
console.log(xhr);
});
Ok, seems to be a problem with the use of jsdom, replaced jsdom with xmldom in util.js
and the parser seems to work fine:
$rdf.Util.parseXML = function(str) {
var dparser;
if ((typeof tabulator != 'undefined' && tabulator.isExtension)) {
dparser = Components.classes["@mozilla.org/xmlextras/domparser;1"].getService(
Components.interfaces.nsIDOMParser);
} else if (typeof module != 'undefined' && module && module.exports){ // Node.js
//var libxmljs = require('libxmljs'); // Was jsdom before 2012-01 then libxmljs but that nonstandard
//return libxmljs.parseXmlString(str);
//var jsdom = require('jsdom');
//var dom = jsdom.jsdom(str, undefined, {} );// html, level, options
//return dom
var DOMParser = require('xmldom').DOMParser;
var dom = new DOMParser().parseFromString(str,'text/xml')
return dom
} else {
dparser = new DOMParser();
}
return dparser.parseFromString(str, 'application/xml');
};
This shouldn't be a problem for RDF/XML, but as far as I saw, the function parseXML
was also used to parse RDFa in the fetcher. Due to the fact that RDFa can be used with HTML (that must not be valid XML), I think this needs further work. Maybe just use jsdom again for parsing when the fetcher detects RDFa?
somehow also related: #67
A patched version that makes use of xmldom can be found here: https://github.com/ckristo/rdflib.js/tree/xmldom
Tried once more to use jsdom for parsing, but with no luck. jsdom does assign wrong namespaces (e.g. for the rdf:RDF
element it assigns some HTML namespace instead of the RDF one).
Anyhow, jsdom is a library for parsing HTML, so maybe its not a bad choice to introduce xmldom for parsing RDF/XML data.
I tried the patched version above, but still get the error. Perhaps I don't understand what the base URI parameter should be. Here's what I'm doing: rskb = new rdflib.IndexedFormula(); rdflib.parse(rdfSource, rskb, 'https://oslclnx2.rtp.raleigh.ibm.com:9443/ccm/rootservices', 'application/rdf+xml'); ... attempting to read an RTC rootservices document. Here's the first few lines of that document: <?xml version="1.0"?>
<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/terms/" xmlns:jfs="http://jazz.net/xmlns/prod/jazz/jfs/1.0/" xmlns:jd="http://jazz.net/xmlns/prod/jazz/discovery/1.0/" xmlns:jdb="http://jazz.net/xmlns/prod/jazz/dashboard/1.0/" xmlns:jp06="http://jazz.net/xmlns/prod/jazz/process/0.6/" xmlns:jp="http://jazz.net/xmlns/prod/jazz/process/1.0/" xmlns:jtp="http://jazz.net/xmlns/prod/jazz/jtp/0.6/" xmlns:ju="http://jazz.net/ns/ui#" xmlns:oslc="http://open-services.net/ns/core#" xmlns:trs="http://jazz.net/ns/trs#" xmlns:trs2="http://open-services.net/ns/core/trs#" rdf:about="https://oslclnx2.rtp.raleigh.ibm.com:9443/ccm/rootservices">
As you can see, rdf:about does have a namespace. Am I using the correct base parameter?
OK, I have it parsing OK now.
@jamsden Any problems with my patch I should fix?
btw: rdf-ext uses a fork of rdflib.js' RDF/XML Parser that also uses xmldom with node.js, see https://github.com/zazukoians/rdf-ext/blob/master/lib/rdfxml-parser.js and https://github.com/zazukoians/rdf-ext/blob/master/lib/utils-node.js
I have been trying with 5 different files and this code:
but I get:
Am I parsing the right way?