[prev in list] [next in list] [prev in thread] [next in thread]
List: mozilla-rdf
Subject: Re: Function to get data list from local RDF
From: Neil Deakin <ndeakin () sympatico ! ca>
Date: 2003-10-14 16:40:39
[Download RAW message or body]
Josiah wrote:
> I am working on a project that utilizes RDF. The RDF file contains a
> list of IP address, similar to this form:
>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> xmlns:nc="http://www.foo.com/NC-rdf#">
> <rdf:Description about="urn:root">
> <nc:links>
> <rdf:Seq>
> <rdf:li><rdf:Description nc:name="10.1.2.3"
> /></rdf:li>
> <rdf:li><rdf:Description nc:name="12.1.2.3"
> /></rdf:li>
> <rdf:li><rdf:Description nc:name="127.0.0.1"
> /></rdf:li>
> </rdf:Seq>
> </nc:links>
> </rdf:Description>
> </rdf:RDF>
>
> What I need to happen is when a user clicks a button, I need to call
> an external program one at a time for each of these IP addresses. I
> have been struggling with how to get these out of the RDF. Trying to
> use the RDF-in-Mozilla FAQ, and other group postings, I have come up
> with this.
>
> var RDF=Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
> RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
> var sourcename = "preferences.rdf";
>
> var datasource=RDF.GetDataSource(sourcename);
> datasource.QueryInterface(Components.interfaces.nsIRDFDataSource);
> var links = RDF.GetResource("urn:root");
> var itr = datasource.ArcLabelsOut(links);
> while(itr.hasMoreElements()){
> var arcLabelOut = itr.getNext();
> // arcLabelOut has one IP address??
> }
That will return the single nc:links arc. You should use getTarget first
var target = ds.getTarget(links,
RDF.GetResource("http://www.foo.com/NC-rdf#links"),true);
Then, you might want to use nsIRDFContainer and nsIRDFContainerUtils to
iterate over a container.
>
> This doesn't work, and doesn't look quite right to me. Am I on the
> right track?
>
> Thanks,
> Josiah
/ Neil
_______________________________________________
Mozilla-rdf mailing list
Mozilla-rdf@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-rdf
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic