Example #1
0
static void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */
{
	xmlNsPtr nsptr, nsdftptr, curns, prevns = NULL;

	if (nodep->type == XML_ELEMENT_NODE) {
		/* Following if block primarily used for inserting nodes created via createElementNS */
		if (nodep->nsDef != NULL) {
			curns = nodep->nsDef;
			while (curns) {
				nsdftptr = curns->next;
				if (curns->href != NULL) {
					if((nsptr = xmlSearchNsByHref(doc, nodep->parent, curns->href)) && 
						(curns->prefix == NULL || xmlStrEqual(nsptr->prefix, curns->prefix))) {
						curns->next = NULL;
						if (prevns == NULL) {
							nodep->nsDef = nsdftptr;
						} else {
							prevns->next = nsdftptr;
						}
						dom_set_old_ns(doc, curns);
						curns = prevns;
					}
				}
				prevns = curns;
				curns = nsdftptr;
			}
		}
		xmlReconciliateNs(doc, nodep);
	}
}
Example #2
0
static void readDNASequenceContent(xmlNode *node) {
	xmlChar *uri;
	xmlChar *path;
	xmlChar *nt;
	DNASequence *seq;
	xmlNode *child_node; // structured xml annotation
	int i;

	// create DNASequence
	uri = getNodeURI(node);
	seq = createDNASequence(DESTINATION, (char *)uri);

	// add nucleotides
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_NUCLEOTIDES;
	if ((nt = getContentsOfNodeMatchingXPath(node, path))) {
		setDNASequenceNucleotides(seq, (char *)nt);
		xmlFree(nt);
	}
	// scan other xml nodes attached to this Annotation for structured xml annotations
	// @TODO factor out this block of code.  This routine is generally used by each of the SBOL core objects
	// but it requires some custom knowledge of the calling object (in this case, Annotation)
	child_node = node->children;
	while (child_node) {
		if (child_node->ns && !isSBOLNamespace(child_node->ns->href)) {
			// copy xml tree and save it in the SBOLDocument object as a structural annotation 
			xmlNode* node_copy = xmlDocCopyNode(child_node, seq->doc->xml_doc, 1);
			node_copy = xmlAddChild(xmlDocGetRootElement(seq->doc->xml_doc), node_copy);
			i = xmlReconciliateNs(seq->doc->xml_doc, xmlDocGetRootElement(seq->doc->xml_doc));
			insertPointerIntoArray(seq->base->xml_annotations, node_copy);
		}
		child_node = child_node->next;
	}
	xmlFree(uri);
}
Example #3
0
static void readCollectionContent(xmlNode *node) {
    Collection *col;
    xmlChar *col_uri;
	xmlNode *child_node; // structured xml annotation
	int i;

    // create Collection
    col_uri = getNodeURI(node);
    col = createCollection(DESTINATION, (char *)col_uri);
    xmlFree(col_uri);

    // add displayID, name, description
    readSBOLCompoundObject(col->base, node);

	// scan other xml nodes attached to this Collection for structured xml annotations
	// @TODO factor out this block of code.  This routine is generally used by each of the SBOL core objects
	// but it requires some custom knowledge of the calling object (in this case, Collection)
	child_node = node->children;
	while (child_node) {
		if (child_node->ns && !isSBOLNamespace(child_node->ns->href)) {
			// copy xml tree and save it in the SBOLDocument object as a structural annotation 
			xmlNode* node_copy = xmlDocCopyNode(child_node, col->doc->xml_doc, 1);
			node_copy = xmlAddChild(xmlDocGetRootElement(col->doc->xml_doc), node_copy);
			i = xmlReconciliateNs(col->doc->xml_doc, xmlDocGetRootElement(col->doc->xml_doc));
			insertPointerIntoArray(col->base->base->xml_annotations, node_copy);
		}
		child_node = child_node->next;
	}

}
Example #4
0
 xmlNode* child_node_list::insert_(iterator pos, xmlNode* child)
 {
     // Check the ownership of the iterator parameter.
     check_ownership_(pos);
     // Unlink the child node from its previous owner.
     xmlUnlinkNode(child);
     // Insert the libxml2 node to this child node list.
     xmlNode* px = 0;
     if (pos == end())
     {
         px = xmlAddChild(raw_, child);
     }
     else
     {
         px = xmlAddPrevSibling(pos->raw(), child);
     }
     if (px == 0)
     {
         std::string what = "fail to insert: xmlAddChild()/xmlAddPrevSibling() returned null";
         throw internal_dom_error(what);
     }
     // Reconciliate XML namespaces as necessary.
     if (px->type == XML_ELEMENT_NODE)
     {
         int count = xmlReconciliateNs(px->doc, px);
         if (count < 0)
         {
             throw internal_dom_error("fail to reconciliate xmlns on the inserted element");
         }
     }
     // Return the inserted libxml2 node.
     return px;
 }
Example #5
0
xmlNode* removeXMLAnnotationFromSBOLObject(SBOLObject* obj, int index, xmlDoc* xml_doc) {
	xmlNode *node = getNthStructuredAnnotationAsXML(obj, index);
	removePointerFromArray(obj->xml_annotations, index);
	xmlUnlinkNode(node);
	// xmlFreeNode(node);
	int i = xmlReconciliateNs(xml_doc, xmlDocGetRootElement(xml_doc));
	return node;
}
Example #6
0
static void readSequenceAnnotationContent(xmlNode *node) {
	SequenceAnnotation *ann;
	xmlChar *ann_uri;
	xmlChar *path;
	xmlChar *contents;
	xmlNode *child_node; // structured xml annotation
	int i;

	// create SequenceAnnotation
	ann_uri = getNodeURI(node);
	ann = createSequenceAnnotation(DESTINATION, (char *)ann_uri);
	xmlFree(ann_uri);

	// add bioStart
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_BIOSTART;
	if ((contents = getContentsOfNodeMatchingXPath(node, path))) {
		setSequenceAnnotationStart(ann, strToInt((char *)contents));
		xmlFree(contents);
	}

	// add bioEnd
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_BIOEND;
        if ((contents = getContentsOfNodeMatchingXPath(node, path))) {
		setSequenceAnnotationEnd(ann, strToInt((char *)contents));
		xmlFree(contents);
	}

	// add strand
	path = BAD_CAST "./" NSPREFIX_SBOL ":" NODENAME_STRAND;
        if ((contents = getContentsOfNodeMatchingXPath(node, path))) {
		setSequenceAnnotationStrand(ann, strToPolarity((char *)contents));
		xmlFree(contents);
	}

	// scan other xml nodes attached to this Annotation for structured xml annotations
	// @TODO factor out this block of code.  This routine is generally used by each of the SBOL core objects
	// but it requires some custom knowledge of the calling object (in this case, Annotation)
	child_node = node->children;
	while (child_node) {
		if (child_node->ns && !isSBOLNamespace(child_node->ns->href)) {
			// copy xml tree and save it in the SBOLDocument object as a structural annotation 
			xmlNode* node_copy = xmlDocCopyNode(child_node, ann->doc->xml_doc, 1);
			node_copy = xmlAddChild(xmlDocGetRootElement(ann->doc->xml_doc), node_copy);
			i = xmlReconciliateNs(ann->doc->xml_doc, xmlDocGetRootElement(ann->doc->xml_doc));
			insertPointerIntoArray(ann->base->xml_annotations, node_copy);
		}
		child_node = child_node->next;
	}
}
Example #7
0
static void readDNAComponentContent(xmlNode *node) {
    DNAComponent *com;
    xmlChar *com_uri;
	xmlChar *path;
	xmlChar *type_property;
	xmlNode *type_node;
	xmlNode *child_node; // structured xml annotation

	PointerArray *results;
	int i;

    // create DNAComponent
    com_uri = getNodeURI(node);
    com = createDNAComponent(DESTINATION, (char *)com_uri);
    xmlFree(com_uri);

    // add displayID, name, description
    readSBOLCompoundObject(com->base, node);
    
    // add type
    path = (unsigned char*)NSPREFIX_RDF ":" NODENAME_TYPE;
	if ((results = getNodesMatchingXPath(node, path))) {
		type_node = (xmlNode *)getNthPointerInArray(results, 0);
		type_property = xmlGetNsProp(type_node, BAD_CAST NODENAME_RESOURCE, BAD_CAST NSURL_RDF);
		setDNAComponentType(com, (char *)type_property);
		xmlFree(results);
	}

	// scan other xml nodes attached to this DNAComponent for structured xml annotations
	// @TODO factor out this block of code.  This routine is generally used by each of the SBOL core objects
	// but it requires some custom knowledge of the calling object (in this case, DNAComponent)
	child_node = node->children;
	while (child_node) {
		if (child_node->ns && !isSBOLNamespace(child_node->ns->href)) {
			// copy xml tree and save it in the SBOLDocument object as a structural annotation 
			xmlNode* node_copy = xmlDocCopyNode(child_node, com->doc->xml_doc, 1);
			node_copy = xmlAddChild(xmlDocGetRootElement(com->doc->xml_doc), node_copy);
			i = xmlReconciliateNs(com->doc->xml_doc, xmlDocGetRootElement(com->doc->xml_doc));
			insertPointerIntoArray(com->base->base->xml_annotations, node_copy);
		}
		child_node = child_node->next;
	}

}
Example #8
0
void addXMLAnnotationToSBOLObject(SBOLObject* obj, xmlNode *node, xmlDoc* xml_doc) {
	node = xmlAddChild(xmlDocGetRootElement(xml_doc), node);
	insertPointerIntoArray(obj->xml_annotations, node);
	int i = xmlReconciliateNs(xml_doc, xmlDocGetRootElement(xml_doc));
	return;
}