[Jslib] How to add sub-sequence in an RDF:Seq?

Wei Wang ww9rivers at sbcglobal.net
Thu Apr 28 21:26:11 EDT 2005


Greetings,

I have half solved the problem. Now I believe either there is a bug or
something in the JSlib/RDF code, or I am misusing something in my code.

The following function now generates "test.rdf (1)" listed below when
run for the first time. The second time it turns the file into "test.rdf
(2)". The third time, it becomes "test.rdf (3)".

function rdf_test ()
{
	var xds = new RDFFile("file:///tmp/test.rdf", 0, "http://9rivers.net/boxman/rdf#", "boxman");
	try
	{
		const xurn = "c9r:boxman";

		// get_root
		var xrootname = "c9r:boxman:devices";
		var xroot = xds.getRootSeq(xrootname);
		if (xds.RDFCUtils.IsContainer(xds.dsource, xroot.getResource()) == false)
		{
			xroot = xds.addRootSeq(xrootname);
			jslibDebug(xrootname + " added as RootSeq.\n");
		}

		// get_net
		jslibDebug("boxman.get_net - adding net sequence to root.\n");
		var xnetname = "test.net";

		//------------------------------------------------------------
		var xnet = xds.getRootSeq(xroot.getSubject() + ":" + xnetname);

		var xdev;
		if (xds.RDFCUtils.IsContainer(xds.dsource, xnet.getResource()) == true)
		{
			jslibDebug(xnet.getSubject() + " is a container.");
			xdev = xnet.getNode("router");
			jslibDebug(xdev.getSubject() + ":boxman:ssid = " + xdev.getAttribute("boxman:ssid"));
		}
		else
		{
			xnet = xroot.addSeq(xnetname);
			xnet.setAttribute("boxman:ssid", xnetname);
			jslibDebug(xnet.getSubject() + " added as a container.");
			xdev = xnet.addNode("router");
		}

		// get_dev
		xdev.setAttribute("boxman:ssid", "test.net");
		xdev.setAttribute("boxman:name", "router");
		xdev.setAttribute("boxman:address", "172.16.8.1");
	}
	catch (ex)
	{
		jslibError(ex);
	}

	xds.flush();
	window.close();
}

_-----------------------------------------------------------------------------------------------------------------
test.rdf (1):
_

<?xml version="1.0"?>
<RDF:RDF xmlns:boxman="http://9rivers.net/boxman/rdf#"
         xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Seq RDF:about="c9r:boxman:devices">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net"/>
  </RDF:Seq>
  <RDF:Description RDF:about="c9r:boxman:devices:test.net:router"
                   boxman:ssid="test.net"
                   boxman:name="router"
                   boxman:address="172.16.8.1" />
  <RDF:Seq RDF:about="c9r:boxman:devices:test.net">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net:router"/>
  </RDF:Seq>
  <RDF:Description RDF:about="c9r:boxman:devices:test.net"
                   boxman:ssid="test.net" />
</RDF:RDF>

_------------------------------------------------------------------------------------------------------------------
test.rdf (2):
_

<?xml version="1.0"?>
<RDF:RDF xmlns:boxman="http://9rivers.net/boxman/rdf#"
         xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Seq RDF:about="c9r:boxman:devices">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net"/>
  </RDF:Seq>
  <RDF:Seq RDF:about="c9r:boxman:devices:test.net">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net:router"/>
  </RDF:Seq>
  <RDF:Description RDF:about="c9r:boxman:devices:test.net"
                   boxman:ssid="test.net" />
  <RDF:Description RDF:about="c9r:boxman:devices:test.net:router"
                   boxman:ssid="test.net"
                   boxman:name="router"
                   boxman:address="172.16.8.1"
                   boxman:ssid="test.net"
                   boxman:name="router"
                   boxman:address="172.16.8.1" />
</RDF:RDF>

_--------------------------------------------------------------------------------------------------------------
test.rdf (3):
_

<?xml version="1.0"?>
<RDF:RDF xmlns:boxman="http://9rivers.net/boxman/rdf#"
         xmlns:NC="http://home.netscape.com/NC-rdf#"
         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <RDF:Seq RDF:about="c9r:boxman:devices">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net"/>
  </RDF:Seq>
  <RDF:Description RDF:about="c9r:boxman:devices:test.net:router"
                   boxman:ssid="test.net"
                   boxman:name="router"
                   boxman:address="172.16.8.1" />
  <RDF:Seq RDF:about="c9r:boxman:devices:test.net">
    <RDF:li RDF:resource="c9r:boxman:devices:test.net:router"/>
  </RDF:Seq>
  <RDF:Description RDF:about="c9r:boxman:devices:test.net"
                   boxman:ssid="test.net" />
</RDF:RDF>

The problem seems to be that the RDFResource.getAttribute() does not
find an existing attribute. I am trying to find exact problem. Any help
is appreciated.

Regards,
-- 
Wei


More information about the Jslib mailing list