[Project_owners] Problems with nsIRDFDataSource.AppendElement()

Axel Hecht axel at pike.org
Thu Jun 9 12:58:47 EDT 2005


Alex Eng wrote:
> In my code, I'm adding a new RDF node to an <RDF:Seq> using the 
> AppendElement() method of the nsIRDFDataSource interface, as per the 
> following code excerpt:
> 
>   var rdfSvc = 
> Components.classes["@..."].getService(Components.interfaces.nsIRDFService);
>   var rdfContainer = 
> Components.classes["@..."].createInstance(Components.interfaces.nsIRDFContainer); 
> 
>   var dataSource;
> 
>   // Get data source, call rdfContainer.Init(), etc....
> 
>   var newNode = rdfSvc.GetAnonymousResource();
>   var prop = rdfSvc.GetResource("http://...#name");
>   var target = rdfSvc.GetLiteral("Joel User");
> 
>   try {
>     dataSource.Assert(newNode, prop, target, true);
>     rdfContainer.AppendElement(newNode);
>   } catch (e) {
>     alert(e);
>   }
>   // ...
> 
> 
> It appears that the line
> 
>    rdfContainer.AppendElement(newNode);
> 
> seems to do nothing - i.e., no new node is added to the <RDF:Seq> 
> container.  Substituting the call to AppendElement() with 
> InsertElementAt(), i.e.,
> 
>    rdfContainer.InsertElementAt(newNode, 1, true);
> 
> won't work, as InsertElementAt() will return NS_ERROR_FAILURE.
> 
> Is there something that I'm doing wrong here?  How can I get 
> AppendElement() to do what it's supposed to do?  Thanks.


This is all smelling like you're not actually having a container in the 
datasource. Note that if you want to start a container from scratch, 
your approach won't do it, containerutils is going to fix that for you. 
If you have an existing Seq, you're making a mistake outside the code 
that you quoted.

Axel


More information about the Project_owners mailing list