Re: how to create in-memory rdf datasource (multi-level) for a XUL tree?

Neil <[email protected]> Wed, 16 Nov 2005 12:57:41 +0000
Newsgroups gmane.comp.mozilla.devel.rdf
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
[email protected] wrote:

>I got problem to populate a XUL tree with an in-memory rdf data source. All sapmle code I've seen so far were just created a tree with only just one top level (eg: http://in.geocities.com/skexz/tuts/xul/in-memory.htm). Is anyone knows how to create a in-memory rdf datasource with structure like below (two levels):
>  
>
Well, that example is a bit convoluted, but do you see how it creates a 
root node, a Seq container, and appends the elements to it? Well, you 
simply do exactly the same thing with the element node - you create a 
Seq for it, and append the children to the Seq. Don't forget to create a 
new RDFC object for each container, unless you're sure you've finished 
with the previous container.

To simplify things you can make the root node the container:

var rootNode = RDF.GetResource("urn:root");

// insert the "top" of the tree, a Seq container
RDFCUtils.MakeSeq(ds, rootNode);
RDFC.Init(ds, rootNode);

You'll also have to change the template:

<conditions>
<treeitem uri="?uri"/>
<member container="?uri" child="?subheading"/>
</conditions>

Which you could then simplify into a basic template:

<template>
<treechildren>
<treeitem uri="rdf:*">
<treerow>
<treecell label="rdf:http://www.bttlindia.com/RDF#id"/>
<treecell label="rdf:http://www.bttlindia.com/RDF#name"/>
<treecell label="rdf:http://www.bttlindia.com/RDF#phone"/>
<treecell label="rdf:http://www.bttlindia.com/RDF#fiscalnumber"/>
</treerow>
</treeitem>
</treechildren>
</template>

Note: this is from memory so I might have some details incorrect.

-- 
Warning: May contain traces of nuts.