if (cellPosVal1.Length() == 0) { rv = node1->GetAttribute(kNameSpaceID_None, sortInfo->kNaturalOrderPosAtom, cellPosVal1); }
XULSortServiceImpl::GetNodeValue(nsIContent *node1, nsIRDFResource *sortProperty, sortPtr sortInfo,				nsIRDFNode **theNode, PRBool &isCollationKey){	nsresult			rv;	nsCOMPtr<nsIRDFResource>	res1;	isCollationKey = PR_FALSE;	nsCOMPtr<nsIDOMXULElement>	dom1 = do_QueryInterface(node1);	if (dom1)	{		if (NS_FAILED(rv = dom1->GetResource(getter_AddRefs(res1))))		{			res1 = nsnull;		}		// Note: don't check for res1 QI failure here.  It only succeeds for RDF nodes,		// but for XUL nodes it will failure; in the failure case, the code below gets		// the cell's text value straight from the DOM	}	else	{		nsCOMPtr<nsIDOMElement>	htmlDom = do_QueryInterface(node1);		if (htmlDom)		{			nsAutoString	htmlID;			if (NS_SUCCEEDED(rv = node1->GetAttribute(kNameSpaceID_None, kIdAtom, htmlID))				&& (rv == NS_CONTENT_ATTR_HAS_VALUE))			{				if (NS_FAILED(rv = gRDFService->GetResource(nsCAutoString(htmlID),					getter_AddRefs(res1))))				{					res1 = nsnull;				}			}		}		else		{			return(NS_ERROR_FAILURE);		}	}		if ((sortInfo->naturalOrderSort == PR_FALSE) && (sortInfo->sortProperty))	{		if (res1)		{			rv = GetResourceValue(res1, sortProperty, sortInfo, theNode, isCollationKey);		}		else		{			rv = NS_RDF_NO_VALUE;		}		if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))		{		        nsCOMPtr<nsIContent>	cell1;		        if (sortInfo->colIndex >= 0)		        {				rv = GetTreeCell(sortInfo, node1, sortInfo->colIndex, getter_AddRefs(cell1));			}			else			{				cell1 = node1;			}			if (cell1)			{				nsAutoString		cellVal1;				if (NS_SUCCEEDED(rv = GetNodeTextValue(sortInfo, cell1, cellVal1)) &&					(rv != NS_RDF_NO_VALUE))				{					nsCOMPtr<nsIRDFLiteral>	nodeLiteral;					gRDFService->GetLiteral(cellVal1.GetUnicode(), getter_AddRefs(nodeLiteral));					*theNode = nodeLiteral;					NS_IF_ADDREF(*theNode);					isCollationKey = PR_FALSE;				}			}		}	}	else if (sortInfo->naturalOrderSort == PR_TRUE)	{		nsAutoString		cellPosVal1;		// check to see if this is a RDF_Seq		// Note: this code doesn't handle the aggregated Seq case especially well		if ((res1) && (sortInfo->db))		{			nsCOMPtr<nsISimpleEnumerator>	arcs;			if (NS_SUCCEEDED(rv = sortInfo->db->ArcLabelsIn(res1, getter_AddRefs(arcs))))			{				PRBool		hasMore = PR_TRUE;				while(hasMore)				{					if (NS_FAILED(rv = arcs->HasMoreElements(&hasMore)))	break;					if (hasMore == PR_FALSE)	break;					nsCOMPtr<nsISupports>	isupports;					if (NS_FAILED(rv = arcs->GetNext(getter_AddRefs(isupports))))	break;					nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);					if (!property)			continue;					// hack: it it looks like a RDF_Seq and smells like a RDF_Seq...					static const char kRDFNameSpace_Seq_Prefix[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#_";					const char	*uri = nsnull;					if (NS_FAILED(rv = property->GetValueConst(&uri)))	continue;					if (!uri)	continue;					if (nsCRT::strncasecmp(uri, kRDFNameSpace_Seq_Prefix, sizeof(kRDFNameSpace_Seq_Prefix)-1))						continue;					cellPosVal1 = uri;					cellPosVal1.Cut(0, sizeof(kRDFNameSpace_Seq_Prefix)-1);					// hack: assume that its a number, so pad out a bit			                nsAutoString	zero("000000");			                if (cellPosVal1.Length() < zero.Length())			                {						cellPosVal1.Insert(zero, 0, zero.Length() - cellPosVal1.Length());			                }					hasMore = PR_FALSE;					break;				}			}		}		if (cellPosVal1.Length() == 0)		{			rv = node1->GetAttribute(kNameSpaceID_None, sortInfo->kNaturalOrderPosAtom, cellPosVal1);		}		if (NS_SUCCEEDED(rv) && (rv != NS_RDF_NO_VALUE))		{			nsCOMPtr<nsIRDFLiteral>	nodePosLiteral;			gRDFService->GetLiteral(cellPosVal1.GetUnicode(), getter_AddRefs(nodePosLiteral));			*theNode = nodePosLiteral;			NS_IF_ADDREF(*theNode);			isCollationKey = PR_FALSE;		}	}	return(rv);}