Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Parsing RDF using nsIRDFContentSink?

0 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Will Sargent

ungelesen,
01.05.2001, 04:43:3701.05.01
an
I have little graphs of RDF serialized as XML, existing as strings in
Javascript. I want to add these graphs into a datasource.

Looking at the source, my best guess is that I need to use nsIRDFContentSink
to parse it into something a datasource will understand.

The problem I have with nsIRDFContentSink is that it only exists as a C++
headerfile. There's no IDL, and without that I don't think I can make it
work with Javascript (I tried the ClassID and the IID to try and create an
instance, without success).

Is this the right route to take, or should I be creating a new datasource
for each graph? If so, is there a clean way to merge the data with the main
datasource (other than listing all the statements out)?

Will.


Chris Waterson

ungelesen,
01.05.2001, 16:56:2401.05.01
an Will Sargent, mozil...@mozilla.org
I think the DOM-friendly way to do this would be to support the notion
of an ``RDF/XML fragment'', which could be parsed into statements using
an ``RDF fragment sink''. This capability does not exist at this time,
but would probably not be hard to implement...

chris

Chris Waterson

ungelesen,
04.05.2001, 03:14:3304.05.01
an Will Sargent
Okay, I have a patch in a related bug that allows you to parse RDF/XML
from anywhere (a JS string, another stream, whatever).

http://bugzilla.mozilla.org/show_bug.cgi?id=35816

I broke out the parsing and serialization stuff from nsRDFXMLDataSource,
so these objects can now be instantiated on their own; e.g., to parse a
string:

var ios = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);

var ds =
Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].
createInstance(Componetns.interfaces.nsIRDFDataSource);

var p = Components.classes["@mozilla.org/rdf/xml-parser;1"]
.createInstance(Components.interfaces.nsIRDFXMLParser);

var uri = ios.newURI("http://foo.com/blah.rdf", null);

p.parseString(ds, uri, "<RDF:RDF xmlns:RDF='...'>...</RDF:RDF>");

Or, alternatively, to serialize an arbitrary datasource:

var ds = /* get this somehow */;

var s = Components.classes["@mozilla.org/rdf/xml-serializer;1"]
.createInstance(Components.interfaces.nsIRDFXMLSerializer);

s.init(ds);

out = { /* minimal impl of nsIOutputStream, Serialize()
will only call |write()| */
function: write(buf, count) { dump(buf); return count; }
};

s.QueryInterface(Components.interfaces.nsIRDFXMLSource)
.Serialize(out);

Also, the RDF/XML that we serialize should be a lot more legible to
humans once I check this in.

chris

Will Sargent

ungelesen,
09.05.2001, 03:25:4709.05.01
an
> Or, alternatively, to serialize an arbitrary datasource:
>
> var ds = /* get this somehow */;
>
> var s = Components.classes["@mozilla.org/rdf/xml-serializer;1"]
> .createInstance(Components.interfaces.nsIRDFXMLSerializer);

Sweet, thank you!

Will.


0 neue Nachrichten