|
Subject: Re: In memory datasoruce examples Newsgroups: gmane.comp.mozilla.devel.rdf Date: 2002-09-17 13:38:16 GMT (6 years, 41 weeks, 4 days, 14 hours and 55 minutes ago) Hi Adam, I could make it work. Tree object was not avaialble to script as it was defined after the script file. I wraped your code in a method and pointed it to the window.onload. It is working now. I am still interested in the code of getService. You have passed the strings to fucntion where as the QueryInterface takes "Interface" as an argument. I am new to javaScript. Raj Adam Fletcher wrote: > Raj, > > Here's a simple example, of populating a non-indented tree, whose XUL > looks like this: > > <tree datasources="rdf:null" ref="urn:root" > id="Example-Books-Tree" flex="1" > autostretch="always" > seltype="single" > flags="dont-build-content" > containment="http://home.netscape.com/NC-rdf#subheadings"> > > <template> > <rule> > <conditions> > <treeitem uri="?uri" /> > <triple subject="?uri" > predicate="http://home.netscape.com/NC-rdf#subheadings" > object="?subheadings" /> > <member container="?subheadings" child="?subheading" /> > </conditions> > > <bindings> > <binding subject="?subheading" > predicate="http://home.netscape.com/NC-rdf#title" > object="?name" /> > > > <binding subject="?subheading" > predicate="http://home.netscape.com/NC-rdf#author" > object="?author" /> > > > </bindings> > > <action> > <treechildren> > <treeitem uri="?subheading" > > <treerow > > <treecell label="?title" /> > <treecell label="?author" /> > </treerow> > </treeitem> > </treechildren> > </action> > </rule> > </template> > <treecols> > <treecol id="title" flex="1" label="Book Title" > align="center" sort="?name" /> > <splitter /> > > <treecol id="author" flex="1" label="Author" align="center" > sort="?author"/> > </treecols> > > </tree> > > > Notice a the datasources is set to rdf:null, indicating that we will > create the datasource in memory. > > In our javascript, we then begin creating the datasouce: > > > // get the XPCOM services we need to work with RDF's > var RDF = getService("@mozilla.org/rdf/rdf-service;1", "nsIRDFService"); > var RDFC = getService("@mozilla.org/rdf/container;1","nsIRDFContainer"); > > var RDFCUtils = getService("@mozilla.org/rdf/container-utils;1", > "nsIRDFContainerUtils"); > > var ds = createInstance( > "@mozilla.org/rdf/datasource;1?name=in-memory-datasource", > "nsIRDFDataSource"); > > // create our root nodes > var rootNode = RDF.GetResource("urn:root"); > var seqNode = RDF.GetResource("urn:root:seq"); > > // insert the "top" of the tree, a Seq container > ds.Assert(rootNode, > RDF.GetResource("http://home.netscape.com/NC-rdf#subheadings"), > seqNode, true); > > RDFCUtils.MakeSeq(ds, seqNode); > RDFC.Init(ds, seqNode); > > // get the tree and add the datasource > var tree = windowHandle.document.getElementById(elementID); > tree.database.AddDataSource(ds); > > > // let's add some data. > // add 10 books, 0..9 > for (var bookID = 0; bookID < 10; bookID++) { > var newURI = "urn:root:file:" + bookID; > // add the new element > RDFC.AppendElement(RDF.GetResource(newURI)); > > ds.Assert(RDF.GetResource(newURI), > RDF.GetResource("http://home.netscape.com/NC-rdf#author"), > RDF.GetLiteral("Ayn Rand"), true); > > ds.Assert(RDF.GetResource(newURI), > RDF.GetResource("http://home.netscape.com/NC-rdf#title"), > RDF.GetLiteral("A Bad Book With A Boring Speech, part " + > bookID), true); > } > > tree.builder.rebuild(); > --- > > If you need more information about this, feel free to ask. > > -Adam > > Raj Saini wrote: > >> Hi, >> >> I need in-memory datasource for my application. I dont find any >> working exapmles or documentation where I can get the idea of how to >> create a in-memory datasource. >> >> The examples available on the mozilla website are not working. I >> copied them in a package under chrome directory. There is a note on >> the RDF examples page that these examples should be packaged as jar >> files. Is it not enough to copy them in a correct chrome package >> directory? >> >> Can some one point to me correct documentation or some working examples? >> >> Thanks >> >> Raj Saini >> > |
|
|