private Element createXrefForNode(Node node) throws Exception {
        Element xrefElm = new Element(GPMLConstants.Xref, GPML_NS);
        // Try to get ReferenceEntity
        GKInstance instance = node.getInstance();
        if (instance == null) {
        	Long id = node.getReactomeId();
        	if (id != null) {
                instance = dbAdaptor.fetchInstance(id);
                node.setInstance(instance);
        	}
        }
        GKInstance referenceEntity = null;
        if (instance != null && instance.getSchemClass().isValidAttribute(ReactomeJavaConstants.referenceEntity)) 
            referenceEntity = (GKInstance) instance.getAttributeValue(ReactomeJavaConstants.referenceEntity);
        if (referenceEntity == null) {
            // Use Reactome as default if no reference entity can be found
            xrefElm.setAttribute(GPMLConstants.Database,
                                 "Reactome");
            String id = instance == null ? node.getReactomeId().toString() : getReactomeId(instance);
            if (id == null) {
            	id = instance.getDBID().toString();
            }
            xrefElm.setAttribute(GPMLConstants.ID, id);
        }
        else {
            GKInstance db = (GKInstance) referenceEntity.getAttributeValue(ReactomeJavaConstants.referenceDatabase);
            xrefElm.setAttribute(GPMLConstants.Database, 
                                 db.getDisplayName());
            String identifier = getIdentifierFromReferenceEntity(referenceEntity);
            xrefElm.setAttribute(GPMLConstants.ID,
                                 identifier);
        }
        return xrefElm;
    }