Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

write (assert) to an rdf file

5 views
Skip to first unread message

Fxp

unread,
May 10, 2009, 5:50:40 AM5/10/09
to
Hi,

I have an rdf file in a folder of my extension.

I want to add a new node, exactly the way it is described in the
tutorial:
https://developer.mozilla.org/en/XUL/Template_Guide/RDF_Modifications
.


The function always says it has no assertion for the asserted
triple...and the source file is never changed!!

Can someone tell me what is missing here for the rdf file to be
modified?

Thank you for your help.

François

************* The function

function addDesc(){

var RDF =
Components
.classes["@mozilla.org/rdf/rdf-service;1"]
.getService(Components.interfaces.nsIRDFService);
var datasource = RDF.GetDataSource("chrome://fxdatatree/content/
template-guide-photos5.rdf");

var source = RDF.GetResource("http://www.xulplanet.com/ndeakin/images/
t/obelisk.jpg");
var predicate = RDF.GetResource("http://purl.org/dc/elements/1.1/
description");
var target = RDF.GetLiteral("One of the thirty or so Egyptian
obelisks");

datasource.Assert(source, predicate, target, true);
alert(datasource.HasAssertion(source, predicate, target, true));
}


**************** the rdf file

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:r="http://www.xulplanet.com/rdf/"
xmlns:nso="http://www.daml.org/2001/09/countries/country-
ont#">

<rdf:Seq rdf:about="http://www.xulplanet.com/rdf/myphotos">
<rdf:li rdf:resource="http://www.xulplanet.com/ndeakin/images/t/
palace.jpg"/>
<rdf:li rdf:resource="http://www.xulplanet.com/ndeakin/images/t/
canal.jpg"/>
<rdf:li rdf:resource="http://www.xulplanet.com/ndeakin/images/t/
obelisk.jpg"/>
</rdf:Seq>

<rdf:Description rdf:about="http://www.xulplanet.com/ndeakin/images/
t/palace.jpg"
dc:title="Palace from Above"
dc:date="2005-04-30T14:55:00+01.00"
dc:description="View from the top of the tower
looking east of the Doges Palace">
<r:country resource="http://www.daml.org/2001/09/countries/iso#IT"/
>
</rdf:Description>
<rdf:Description rdf:about="http://www.xulplanet.com/ndeakin/images/
t/canal.jpg"
dc:title="Canal"
dc:date="2005-05-06T10:15:00+01.00">
<r:country resource="http://www.daml.org/2001/09/countries/iso#NL"/
>
</rdf:Description>
<rdf:Description rdf:about="http://www.xulplanet.com/ndeakin/images/
t/obelisk.jpg"
dc:title="Obelisk">
<r:country resource="http://www.daml.org/2001/09/countries/iso#IT"/
>
</rdf:Description>

<nso:Country about="http://www.daml.org/2001/09/countries/iso#IT"
dc:title="Italy"/>

<nso:Country about="http://www.daml.org/2001/09/countries/iso#NL"
dc:title="Netherlands"/>
</rdf:RDF>

Neil Deakin

unread,
May 10, 2009, 8:11:49 AM5/10/09
to
Fxp wrote:

> The function always says it has no assertion for the asserted
> triple...and the source file is never changed!!
>
> Can someone tell me what is missing here for the rdf file to be
> modified?
>

You can't modify rdf loaded from chrome urls.

Fxp

unread,
May 11, 2009, 2:13:28 PM5/11/09
to
On May 10, 2:11 pm, Neil Deakin <enndea...@sympatico.ca> wrote:

>
> You can't modify rdf loaded from chrome urls.

Thank you Neil, I will try a file:/// uri, and check if the change is
made.

Regards

François

Fxp

unread,
May 14, 2009, 1:53:19 PM5/14/09
to
Thank you again Neil, it works fine.

I just leave here the complete code of the function, because for the
modifications to be writen to the file, you have to use the
"nsIRDFRemoteDataSource" interface, and its "flush" method.

function addDesc(){
var datasource = RDF.GetDataSource("file:///F:/xampp/htdocs/
extensionFirefoxDezip/fxdatatree/chrome/content/template-guide-
photos5.rdf");
//var datasource = RDF.GetDataSource("chrome://fxdatatree/content/
template-guide-photos5.rdf");
var remote = datasource.QueryInterface
(Components.interfaces.nsIRDFRemoteDataSource);

var source = RDF.GetResource("http://www.xulplanet.com/ndeakin/images/
t/obelisk.jpg");
var predicate = RDF.GetResource("http://purl.org/dc/elements/1.1/
description");

var target = RDF.GetLiteral("One of the twenty or so Egyptian
obelisks");

datasource.Assert(source, predicate, target, true);
remote.Flush();
alert("done");
}


Hope this helps

François

0 new messages