PRInt32 theEnd = oneLiner.Find("\"");
theEnd = oneLiner.Find("\"");
RelatedLinksStreamListener::OnDataAvailable(nsIURI* aURL, nsIInputStream *aIStream, PRUint32 aLength){	nsresult	rv = NS_OK;	if (aLength > 0)	{		nsAutoString	line;		if (mLine)		{			line += mLine;			delete	[]mLine;			mLine = nsnull;		}		char	buffer[257];		while (aLength > 0)		{			PRUint32	count=0, numBytes = (aLength > sizeof(buffer)-1 ? sizeof(buffer)-1 : aLength);			if (NS_FAILED(rv = aIStream->Read(buffer, numBytes, &count)))			{				printf("Related Links datasource read failure.\n");				break;			}			if (numBytes != count)			{				printf("Related Links datasource read # of bytes failure.\n");				break;			}			buffer[count] = '\0';			line += buffer;			aLength -= count;		}		while (PR_TRUE)		{			PRInt32 eol = line.FindCharInSet("\r\n");			if (eol < 0)			{				if (mLine)				{					delete []mLine;					mLine = nsnull;				}				mLine = line.ToNewCString();				break;			}			nsAutoString	oneLiner("");			if (eol >= 0)			{				line.Left(oneLiner, eol);				line.Cut(0, eol+1);			}			if (mLine)			{				delete []mLine;				mLine = nsnull;			}			mLine = line.ToNewCString();			if (oneLiner.Length() < 1)	return(rv);//			printf("RL: '%s'\n", oneLiner.ToNewCString());			// yes, very primitive RDF parsing follows			nsAutoString	child(""), title("");			// get href			PRInt32 theStart = oneLiner.Find("<child href=\"");			if (theStart == 0)			{				// get child href				theStart += PL_strlen("<child href=\"");				oneLiner.Cut(0, theStart);				PRInt32 theEnd = oneLiner.Find("\"");				if (theEnd > 0)				{					oneLiner.Mid(child, 0, theEnd);				}				// get child name				theStart = oneLiner.Find("name=\"");				if (theStart >= 0)				{					theStart += PL_strlen("name=\"");					oneLiner.Cut(0, theStart);					PRInt32 theEnd = oneLiner.Find("\"");					if (theEnd > 0)					{						oneLiner.Mid(title, 0, theEnd);					}				}			}			// check for separator			else if ((theStart = oneLiner.Find("<child instanceOf=\"Separator1\"/>")) == 0)			{				nsCOMPtr<nsIRDFResource>	newSeparator;				nsAutoString			rlRoot(kURINC_RelatedLinksRoot);				if (NS_SUCCEEDED(rv = CreateAnonymousResource(rlRoot, &newSeparator)))				{					mDataSource->Assert(newSeparator, kRDF_type, kNC_BookmarkSeparator, PR_TRUE);					PRInt32		numParents = mParentArray.Count();					if (numParents > 0)					{						nsIRDFResource	*parent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));						mDataSource->Assert(parent, kNC_Child, newSeparator, PR_TRUE);					}				}			}			else			{				theStart = oneLiner.Find("<Topic name=\"");				if (theStart == 0)				{					// get topic name					theStart += PL_strlen("<Topic name=\"");					oneLiner.Cut(0, theStart);					PRInt32 theEnd = oneLiner.Find("\"");					if (theEnd > 0)					{						oneLiner.Mid(title, 0, theEnd);					}					nsCOMPtr<nsIRDFResource>	newTopic;					nsAutoString			rlRoot(kURINC_RelatedLinksRoot);					if (NS_SUCCEEDED(rv = CreateAnonymousResource(rlRoot, &newTopic)))					{						if (title.Length() > 0)						{							char *name = title.ToNewCString();							if (nsnull != name)							{								nsAutoString	theName(name);								nsCOMPtr<nsIRDFLiteral> nameLiteral;								if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(theName.GetUnicode(), getter_AddRefs(nameLiteral))))								{									mDataSource->Assert(newTopic, kNC_Name, nameLiteral, PR_TRUE);								}#ifdef	DEBUG								for (PRInt32 i=0; i<mParentArray.Count(); i++)	printf("    ");								printf("Topic: '%s'\n", name);#endif								delete [] name;							}						}						PRInt32		numParents = mParentArray.Count();						if (numParents > 0)						{							nsIRDFResource	*parent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));							mDataSource->Assert(parent, kNC_Child, newTopic, PR_TRUE);						}						mParentArray.AppendElement(newTopic);					}				}				else				{					theStart = oneLiner.Find("</Topic>");					if (theStart == 0)					{						PRInt32		numParents = mParentArray.Count();						if (numParents > 0)						{							mParentArray.RemoveElementAt(numParents - 1);						}#ifdef	DEBUG						for (PRInt32 i=0; i<mParentArray.Count(); i++)	printf("    ");						printf("Topic ends.\n");#endif					}				}			}			if (child.Length() > 0)			{				char	*url = child.ToNewCString();				if (nsnull != url)				{					nsCOMPtr<nsIRDFResource>	relatedLinksChild;					PRInt32		numParents = mParentArray.Count();					if (numParents > 1)					{						nsAutoString	rlRoot(kURINC_RelatedLinksRoot);						rv = CreateAnonymousResource(rlRoot, &relatedLinksChild);					}					else					{						rv = gRDFService->GetResource(url, getter_AddRefs(relatedLinksChild));					}					if (NS_SUCCEEDED(rv))					{											if (title.Length() > 0)						{							char *name = title.ToNewCString();							if (nsnull != name)							{								nsAutoString		theName(name);								nsCOMPtr<nsIRDFLiteral>	nameLiteral;								if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(theName.GetUnicode(), getter_AddRefs(nameLiteral))))								{									mDataSource->Assert(relatedLinksChild, kNC_Name, nameLiteral, PR_TRUE);								}#ifdef	DEBUG								for (PRInt32 i=0; i<mParentArray.Count(); i++)	printf("    ");								printf("Name: '%s'  URL: '%s'\n", name, url);#endif								delete [] name;							}						}						if (numParents > 0)						{							nsIRDFResource	*parent = (nsIRDFResource *)(mParentArray.ElementAt(numParents - 1));							mDataSource->Assert(parent, kNC_Child, relatedLinksChild, PR_TRUE);						}					}					delete []url;				}			}		}	}	return(rv);}