Retreiving all the children of a resource with JavaScript

[email protected] 21 Jun 2005 02:47:46 -0700
Newsgroups gmane.comp.mozilla.devel.rdf
Organization http://groups.google.com
Message-ID <[email protected]>
Hi all!

I'm having some problem retreiving all the childrens of a resource. I
have some URLS categorized. My goal is to echo the url and name for
each resource in a category. Nothing more.

The RDF is validated. I get some values echoed. But not the url and
name of each url...



My JavaScript code:
var rdf =
Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
var ds = rdf.GetDataSourceBlocking("chrome://myapp/locale/urls.rdf");
var ds = ds.QueryInterface(Components.interfaces.nsIRDFDataSource);

var websearch = rdf.GetResource("http://www.domain.com/websearch");

var url       = rdf.GetResource("http://www.domain.com/rdf/url");
var name      = rdf.GetResource("http://www.domain.com/rdf/name");

var targets   = ds.ArcLabelsOut(websearch);
while (targets.hasMoreElements()){
	var predicate = targets.getNext();

	if (predicate instanceof Components.interfaces.nsIRDFResource){
		alert("Predicate : " + predicate.Value + " is ...");

		var target = ds.GetTarget(websearch, predicate, true);

		if (target instanceof Components.interfaces.nsIRDFResource){
			alert("Resource: " + target.Value);

			var url  = ds.GetTarget(target, url,  true);
			var name = ds.GetTarget(target, name, true);

			alert(name + " : " + url); // becomes null!!
		}
	}
}




My RDF file:

<?xml version="1.0"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:urls="http://www.domain.com/rdf/">

       <rdf:Description
rdf:about="http://www.domain.com/websearch/yahoo">
         <urls:name>Yahoo</urls:name>

<urls:url>http://search.yahoo.com/search?p=query&amp;ei=UTF-8</urls:url>
       </rdf:Description>

       <rdf:Description
rdf:about="http://www.domain.com/websearch/ask">
         <urls:name>Ask Jeeves</urls:name>
         <urls:url>http://web.ask.com/web?q=query</urls:url>
       </rdf:Description>

       <rdf:Description
rdf:about="http://www.domain.com/moviesearch/rottentomatoes">
         <urls:name>Rotten Tomatoes</urls:name>

<urls:url>http://www.rottentomatoes.com/search/search.php?searchby=movies&amp;search=query</urls:url>
       </rdf:Description>

  <rdf:Seq rdf:about="http://www.domain.com/all-urls">
    <rdf:li>
      <rdf:Seq rdf:about="http://www.domain.com/websearch">
		<rdf:li rdf:resource="http://www.domain.com/websearch/yahoo"/>
		<rdf:li rdf:resource="http://www.domain.com/websearch/ask"/>
      </rdf:Seq>
    </rdf:li>
    <rdf:li>
      <rdf:Seq rdf:about="http://www.domain.com/moviesearch">
        <rdf:li
rdf:resource="http://www.domain.com/moviesearch/rottentomatoes"/>
      </rdf:Seq>
    </rdf:li>
  </rdf:Seq>

</rdf:RDF>