Esempio n. 1
0
File: xpath.c Progetto: jetaber/XML
USER_OBJECT_
RS_XML_copyNodesToDoc(USER_OBJECT_ s_node, USER_OBJECT_ s_doc, USER_OBJECT_ manageMemory)
{
 xmlDocPtr doc;
 xmlNodePtr node, ptr;
 int len, i;
 SEXP ans;

 doc = (xmlDocPtr) R_ExternalPtrAddr(s_doc);

 if(TYPEOF(s_node) == EXTPTRSXP) {
     node = (xmlNodePtr) R_ExternalPtrAddr(s_node);
     ptr = xmlDocCopyNode(node, doc, 1);
     return(R_createXMLNodeRef(ptr, manageMemory));
 }

 len = Rf_length(s_node);
 PROTECT(ans = NEW_LIST(len));
 for(i = 0; i < len; i++) {
     node = (xmlNodePtr) R_ExternalPtrAddr(VECTOR_ELT(s_node, i));
     ptr = xmlDocCopyNode(node, doc, 1);
     SET_VECTOR_ELT(ans, i, R_createXMLNodeRef(ptr, manageMemory)); 
 }
 UNPROTECT(1);
 return(ans);
}
Esempio n. 2
0
 XMLNode XMLNode::NewChild(const XMLNode& node, int n, bool global_order) {
   if (node_ == NULL)
     return XMLNode();
   if (node.node_ == NULL)
     return XMLNode();
   if (node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   // TODO: Add new attribute if 'node' is attribute
   if (node.node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   xmlNodePtr new_node = xmlDocCopyNode(node.node_, node_->doc, 1);
   if (new_node == NULL)
     return XMLNode();
   if (n < 0)
     return XMLNode(xmlAddChild(node_, new_node));
   std::string name;
   xmlNsPtr ns = GetNamespace(new_node);
   if (ns != NULL) {
     if (ns->prefix != NULL)
       name = (char*)ns->prefix;
     name += ":";
   }
   if (new_node->name)
     name += (char*)(new_node->name);
   XMLNode old_node = global_order ? Child(n) : operator[](name)[n];
   if (!old_node)
     // TODO: find last old_node
     return XMLNode(xmlAddChild(node_, new_node));
   if (old_node)
     return XMLNode(xmlAddPrevSibling(old_node.node_, new_node));
   return XMLNode(xmlAddChild(node_, new_node));
 }
Esempio n. 3
0
int xml_validate(struct xml_node_ctx *ctx, xml_node_t *node,
		 const char *xml_schema_fname, char **ret_err)
{
	xmlDocPtr doc;
	xmlNodePtr n;
	xmlSchemaParserCtxtPtr pctx;
	xmlSchemaValidCtxtPtr vctx;
	xmlSchemaPtr schema;
	int ret;
	struct str_buf errors;

	if (ret_err)
		*ret_err = NULL;

	doc = xmlNewDoc((xmlChar *) "1.0");
	if (doc == NULL)
		return -1;
	n = xmlDocCopyNode((xmlNodePtr) node, doc, 1);
	if (n == NULL) {
		xmlFreeDoc(doc);
		return -1;
	}
	xmlDocSetRootElement(doc, n);

	os_memset(&errors, 0, sizeof(errors));

	pctx = xmlSchemaNewParserCtxt(xml_schema_fname);
	xmlSchemaSetParserErrors(pctx, (xmlSchemaValidityErrorFunc) add_str,
				 (xmlSchemaValidityWarningFunc) add_str,
				 &errors);
	schema = xmlSchemaParse(pctx);
	xmlSchemaFreeParserCtxt(pctx);

	vctx = xmlSchemaNewValidCtxt(schema);
	xmlSchemaSetValidErrors(vctx, (xmlSchemaValidityErrorFunc) add_str,
				(xmlSchemaValidityWarningFunc) add_str,
				&errors);

	ret = xmlSchemaValidateDoc(vctx, doc);
	xmlSchemaFreeValidCtxt(vctx);
	xmlFreeDoc(doc);
	xmlSchemaFree(schema);

	if (ret == 0) {
		os_free(errors.buf);
		return 0;
	} else if (ret > 0) {
		if (ret_err)
			*ret_err = errors.buf;
		else
			os_free(errors.buf);
		return -1;
	} else {
		if (ret_err)
			*ret_err = errors.buf;
		else
			os_free(errors.buf);
		return -1;
	}
}
Esempio n. 4
0
Variant c_XMLReader::t_expand(const Object& basenode /* = null */) {
  p_DOMDocument doc;
  xmlDocPtr docp = nullptr;

  if (!basenode.isNull()) {
    c_DOMNode *dombasenode = basenode.getTyped<c_DOMNode>();
    doc = dombasenode->doc();
    docp = (xmlDocPtr) doc->m_node;
    if (docp == nullptr) {
      raise_warning("Invalid State Error");
      return false;
    }
  } else {
    doc = (p_DOMDocument) SystemLib::AllocDOMDocumentObject();
  }

  if (m_ptr) {
    xmlNodePtr node = xmlTextReaderExpand(m_ptr);
    if (node == nullptr) {
      raise_warning("An Error Occurred while expanding");
      return false;
    } else {
      xmlNodePtr nodec = xmlDocCopyNode(node, docp, 1);
      if (nodec == nullptr) {
        raise_notice("Cannot expand this node type");
        return false;
      } else {
        return php_dom_create_object(nodec, doc, false);
      }
    }
  }

  raise_warning("Load Data before trying to read");
  return false;
}
Esempio n. 5
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);
}
Esempio n. 6
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;
	}

}
Esempio n. 7
0
static VALUE rxml_node_remove_ex(VALUE self)
{
  xmlNodePtr xnode, xresult;
  xnode = rxml_get_xnode(self);

  /* First unlink the node from its parent. */
  xmlUnlinkNode(xnode);

  /* Now copy the node we want to remove and make the
     current Ruby object point to it.  We do this because
     a node has a number of dependencies on its parent
     document - its name (if using a dictionary), entities,
     namespaces, etc.  For a node to live on its own, it
     needs to get its own copies of this information.*/
  xresult = xmlDocCopyNode(xnode, NULL, 1);
  
  /* Now free the original node. */
  xmlFreeNode(xnode);

  /* Now wrap the new node */
  RDATA(self)->data = xresult;
  xresult->_private = (void*) self;

  /* Now return the removed node so the user can
     do something with it.*/
  return self;
}
Esempio n. 8
0
/*
 * call-seq:
 *  dup
 *  dup(depth)
 *  dup(depth, new_parent_doc)
 *
 * Copy this node.
 * An optional depth may be passed in. 0 is a shallow copy, 1 (the default) is a deep copy.
 * An optional new_parent_doc may also be passed in, which will be the new
 * node's parent document. Defaults to the current node's document.
 * current document.
 */
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
{
  VALUE r_level, r_new_parent_doc;
  int level;
  int n_args;
  xmlDocPtr new_parent_doc;
  xmlNodePtr node, dup;

  Data_Get_Struct(self, xmlNode, node);

  n_args = rb_scan_args(argc, argv, "02", &r_level, &r_new_parent_doc);

  if (n_args < 1) {
    r_level = INT2NUM((long)1);
  }
  level = (int)NUM2INT(r_level);

  if (n_args < 2) {
    new_parent_doc = node->doc;
  } else {
    Data_Get_Struct(r_new_parent_doc, xmlDoc, new_parent_doc);
  }

  dup = xmlDocCopyNode(node, new_parent_doc, level);
  if(dup == NULL) { return Qnil; }

  nokogiri_root_node(dup);

  return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
}
Esempio n. 9
0
xmlDocPtr copy_node_to_doc(const xmlNodePtr node)
{
  g_return_val_if_fail(node, NULL);
  xmlDocPtr doc = xmlNewDoc((xmlChar *) XML_DEFAULT_VERSION);
  xmlNodePtr root = xmlDocCopyNode(node, doc, 1);// copies recursively
  xmlDocSetRootElement(doc, root);
  g_assert(doc);
  return doc;
}
Esempio n. 10
0
void xml_parser_copy_node(WsXmlNodeH src, WsXmlNodeH dst)
{
	if (src && dst) {
		xmlNodePtr x = xmlDocCopyNode((xmlNodePtr) src,
				   ((xmlDocPtr) src)->doc, 1);
		if (x)
			xmlAddChild((xmlNodePtr) dst, x);
	}
}
Esempio n. 11
0
static void _importNode(Request& r, MethodParams& params) {
	xmlNode& importedNode=as_node(params, 0, "importedNode must be node");
	bool deep=params.as_bool(1, "deep must be bool", r);

	VXdoc& vdoc=GET_SELF(r, VXdoc);
	xmlDoc& xmldoc=vdoc.get_xmldoc();

	xmlNode *node=xmlDocCopyNode(&importedNode, &xmldoc, deep?1: 0);
	writeNode(r, vdoc, node);
}
Esempio n. 12
0
Element * Document::SetRoot(const Node *nodeToCopy, bool recursive)
{
    xmlNodePtr theCopy = xmlDocCopyNode(const_cast<xmlNodePtr>(nodeToCopy->xml()), xml(), (recursive ? 1 : 0));
    if ( theCopy == nullptr )
        throw InternalError("Failed to copy new root node.");
    
    xmlNodePtr oldRoot = xmlDocSetRootElement(xml(), theCopy);
    if ( oldRoot != nullptr )
        xmlFreeNode(oldRoot);       // the glue will delete any associated C++ object
    return Root();
}
Esempio n. 13
0
// Node cloneNode(in boolean deep);
static void _cloneNode(Request& r, MethodParams& params) {
	bool deep=params.as_bool(0, "deep must be bool", r);

	VXnode& vnode=GET_SELF(r, VXnode);
	xmlNode& selfNode=vnode.get_xmlnode();
	VXdoc& vxdoc=vnode.get_vxdoc();
	xmlDoc& xmldoc=vxdoc.get_xmldoc();

	xmlNode* retNode=xmlDocCopyNode(&selfNode, &xmldoc, deep?1: 0);
	// write out result
	writeNode(r, vxdoc, retNode);
}
Esempio n. 14
0
/**
 * xmlXIncludeCopyNode:
 * @ctxt:  the XInclude context
 * @target:  the document target
 * @source:  the document source
 * @elem:  the element
 *
 * Make a copy of the node while preserving the XInclude semantic
 * of the Infoset copy
 */
static xmlNodePtr
xmlXIncludeCopyNode(xmlXIncludeCtxtPtr ctxt, xmlDocPtr target,
                    xmlDocPtr source, xmlNodePtr elem) {
    xmlNodePtr result = NULL;

    if ((ctxt == NULL) || (target == NULL) || (source == NULL) ||
            (elem == NULL))
        return(NULL);
    if (elem->type == XML_DTD_NODE)
        return(NULL);
    result = xmlDocCopyNode(elem, target, 1);
    return(result);
}
Esempio n. 15
0
void SoapExecution::prepareQuery() {
    string xml = "<query xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>";
    xml += getSql();
    xml += "</query>";
    LOG_DEBUG("about to parse");
    xmlDocPtr doc = xmlParseDoc((xmlChar*)xml.c_str());
    xmlNodePtr queryElement = xmlDocGetRootElement(doc);
    xmlNodePtr tmp = queryElement->children;

    xmlNodePtr inputNode = nullptr;
    xmlNodePtr outputNode = nullptr;

    while(tmp) {
        if (tmp->type == XML_ELEMENT_NODE) {
            if (inputNode == nullptr) {
                inputNode = tmp;
            } else {
                outputNode = tmp;
            }
        }
        tmp = tmp->next;
    }

    if (inputNode == nullptr || outputNode == nullptr) {
        THROW_EXC("input or output node missing.");
    }

    LOG_DEBUG("inputNode = " << inputNode->name);
    LOG_DEBUG("outputNode = " << outputNode->name);;

    xmlNodePtr inputQuery = xmlDocCopyNode(inputNode,doc,1);
    xmlNodePtr outputQuery = xmlDocCopyNode(outputNode,doc,1);

    assert(getInPorts().size() == 1);

    inputTemplate.setStylesheet(inputQuery);
    outputTemplate.setStylesheet(outputQuery);

}
Esempio n. 16
0
int xml_validate_dtd(struct xml_node_ctx *ctx, xml_node_t *node,
		     const char *dtd_fname, char **ret_err)
{
	xmlDocPtr doc;
	xmlNodePtr n;
	xmlValidCtxt vctx;
	xmlDtdPtr dtd;
	int ret;
	struct str_buf errors;

	if (ret_err)
		*ret_err = NULL;

	doc = xmlNewDoc((xmlChar *) "1.0");
	if (doc == NULL)
		return -1;
	n = xmlDocCopyNode((xmlNodePtr) node, doc, 1);
	if (n == NULL) {
		xmlFreeDoc(doc);
		return -1;
	}
	xmlDocSetRootElement(doc, n);

	os_memset(&errors, 0, sizeof(errors));

	dtd = xmlParseDTD(NULL, (const xmlChar *) dtd_fname);
	if (dtd == NULL) {
		xmlFreeDoc(doc);
		return -1;
	}

	os_memset(&vctx, 0, sizeof(vctx));
	vctx.userData = &errors;
	vctx.error = add_str;
	vctx.warning = add_str;
	ret = xmlValidateDtd(&vctx, doc, dtd);
	xmlFreeDoc(doc);
	xmlFreeDtd(dtd);

	if (ret == 1) {
		os_free(errors.buf);
		return 0;
	} else {
		if (ret_err)
			*ret_err = errors.buf;
		else
			os_free(errors.buf);
		return -1;
	}
}
Esempio n. 17
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;
	}
}
Esempio n. 18
0
/*
 * call-seq:
 *  dup
 *
 * Copy this node.  An optional depth may be passed in, but it defaults
 * to a deep copy.  0 is a shallow copy, 1 is a deep copy.
 */
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
{
  VALUE level;

  if(rb_scan_args(argc, argv, "01", &level) == 0)
    level = INT2NUM(1);

  xmlNodePtr node, dup;
  Data_Get_Struct(self, xmlNode, node);

  dup = xmlDocCopyNode(node, node->doc, NUM2INT(level));
  if(dup == NULL) return Qnil;

  return Nokogiri_wrap_xml_node(dup);
}
Esempio n. 19
0
void snippets_export_node(xmlNodePtr node, const gchar *filename) {
	xmlNodePtr newnode=NULL, cur=NULL;
	xmlDocPtr newdoc; 
	
	newdoc = xmlNewDoc((const xmlChar *)"1.0");
	cur = xmlNewDocNode(newdoc,NULL, (const xmlChar *)"snippets",NULL);
	xmlDocSetRootElement(newdoc, cur);
	
	newnode = xmlDocCopyNode(node, newdoc, TRUE);
	DEBUG_MSG("snippets_export_node, cur=%p, newdoc=%p, newnode=%p\n",cur,newdoc,newnode);
	xmlAddChild(cur, newnode);

	xmlSaveFormatFile(filename, newdoc, 1);
	xmlFreeDoc(newdoc);
}
Esempio n. 20
0
/*
 * call-seq:
 *    document.import(node) -> XML::Node
 *
 * Creates a copy of the node that can be inserted into the
 * current document.
 */
static VALUE rxml_document_import(VALUE self, VALUE node)
{
  xmlDocPtr xdoc;
  xmlNodePtr xnode, xresult;

  Data_Get_Struct(self, xmlDoc, xdoc);
  Data_Get_Struct(node, xmlNode, xnode);

  xresult = xmlDocCopyNode(xnode, xdoc, 1);

  if (xresult == NULL)
    rxml_raise(&xmlLastError);

  return rxml_node_wrap(xresult);
}
Esempio n. 21
0
xmlNode* htmlParseFragmentAsDoc(void *doc, void *buffer, int buffer_len, void *url, void *encoding, int options, void *error_buffer, int error_buffer_len) {
	xmlDoc* tmpDoc = NULL;
	xmlNode* tmpRoot = NULL;
	tmpDoc = htmlReadMemory((char*)buffer, buffer_len, (char*)url, (char*)encoding, options);
	if (tmpDoc == NULL) {
		return NULL;
	}
	tmpRoot = xmlDocGetRootElement(tmpDoc);
	if (tmpRoot == NULL) {
		return NULL;
	}
	tmpRoot = xmlDocCopyNode(tmpRoot, doc, 1);
	xmlFreeDoc(tmpDoc);
	return tmpRoot;
}
Esempio n. 22
0
 void XMLNode::Replace(const XMLNode& node) {
   if (node_ == NULL)
     return;
   if (node.node_ == NULL)
     return;
   if (node_->type != XML_ELEMENT_NODE)
     return;
   if (node.node_->type != XML_ELEMENT_NODE)
     return;
   xmlNodePtr new_node = xmlDocCopyNode(node.node_, node_->doc, 1);
   if (new_node == NULL)
     return;
   xmlReplaceNode(node_, new_node);
   xmlFreeNode(node_);
   node_ = new_node;
   return;
 }
Esempio n. 23
0
/*
 * call-seq:
 *  dup
 *
 * Copy this node.  An optional depth may be passed in, but it defaults
 * to a deep copy.  0 is a shallow copy, 1 is a deep copy.
 */
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
{
  VALUE level;
  xmlNodePtr node, dup;

  if(rb_scan_args(argc, argv, "01", &level) == 0)
    level = INT2NUM((long)1);

  Data_Get_Struct(self, xmlNode, node);

  dup = xmlDocCopyNode(node, node->doc, (int)NUM2INT(level));
  if(dup == NULL) return Qnil;

  NOKOGIRI_ROOT_NODE(dup);

  return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
}
Esempio n. 24
0
/* {{{ proto bool XMLReader::expand()
Moves the position of the current instance to the next node in the stream. */
PHP_METHOD(xmlreader, expand)
{
#ifdef HAVE_DOM
	zval *id, *basenode = NULL;
	int ret;
	xmlreader_object *intern;
	xmlNode *node, *nodec;
	xmlDocPtr docp = NULL;
	php_libxml_node_object *domobj = NULL;

	id = ZEND_THIS;
	if (zend_parse_parameters(ZEND_NUM_ARGS(), "|O!", &basenode, dom_node_class_entry) == FAILURE) {
		return;
	}

	if (basenode != NULL) {
		NODE_GET_OBJ(node, basenode, xmlNodePtr, domobj);
		docp = node->doc;
	}

	intern = Z_XMLREADER_P(id);

	if (intern && intern->ptr) {
		node = xmlTextReaderExpand(intern->ptr);

		if (node == NULL) {
			php_error_docref(NULL, E_WARNING, "An Error Occurred while expanding ");
			RETURN_FALSE;
		} else {
			nodec = xmlDocCopyNode(node, docp, 1);
			if (nodec == NULL) {
				php_error_docref(NULL, E_NOTICE, "Cannot expand this node type");
				RETURN_FALSE;
			} else {
				DOM_RET_OBJ(nodec, &ret, (dom_object *)domobj);
			}
		}
	} else {
		php_error_docref(NULL, E_WARNING, "Load Data before trying to expand");
		RETURN_FALSE;
	}
#else
	php_error(E_WARNING, "DOM support is not enabled");
	return;
#endif
}
Esempio n. 25
0
int xml_parser_create_doc_by_import(WsXmlDocH wsDoc, WsXmlNodeH node)
{
	xmlDocPtr doc;
	xmlNodePtr rootNode;

	if ((doc = xmlNewDoc(BAD_CAST "1.0")) == NULL) {
		if (doc)
			xmlFreeDoc(doc);
		return 0;
	} else {
		doc->_private = wsDoc;
		wsDoc->parserDoc = doc;
		rootNode = xmlDocCopyNode((xmlNodePtr) node, doc, 1);
		xmlDocSetRootElement(doc, rootNode);
		return 1;
	}
}
Esempio n. 26
0
File: xpath.c Progetto: jetaber/XML
USER_OBJECT_
RS_XML_createDocFromNode(USER_OBJECT_ s_node)
{
 xmlDocPtr doc;
 xmlNodePtr node, ptr;
 SEXP ans;

 node = (xmlNodePtr) R_ExternalPtrAddr(s_node);
 doc = xmlNewDoc(CHAR_TO_XMLCHAR("1.0"));
 R_numXMLDocs++;

 ptr = xmlDocCopyNode(node, doc, 1);
 node = (xmlNodePtr) doc;
 xmlAddChild(node, ptr);

 ans = R_createXMLDocRef(doc);
 return(ans);
}
Esempio n. 27
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;
	}

}
Esempio n. 28
0
std::shared_ptr<Node> Node::CopyIn(std::shared_ptr<const Node> nodeToCopy, bool recursive)
{
    if ( nodeToCopy == nullptr )
        return nullptr;
    
    // complains about the difference between 'const xmlNode *' and 'xmlNode const *' ...
    xmlNodePtr theCopy = xmlDocCopyNode(const_cast<_xmlNode *>(nodeToCopy->xml()), _xml->doc, recursive ? 1 : 0);
    if ( theCopy == nullptr )
        throw InternalError("Unable to copy node", xmlGetLastError());
    
    xmlNode * added = xmlAddChild(_xml, theCopy);
    if ( added == nullptr )
    {
        xmlFreeNode(theCopy);
        throw InternalError("Unable to add copied node as a new child", xmlGetLastError());
    }
    
    // if added != theCopy, then theCopy has already been freed
    return Wrapped<Node, _xmlNode>(added);
}
Esempio n. 29
0
 void XMLNode::New(XMLNode& new_node) const {
   if (new_node.is_owner_ && new_node.node_)
     xmlFreeDoc(new_node.node_->doc);
   new_node.is_owner_ = false;
   new_node.node_ = NULL;
   if (node_ == NULL)
     return;
   // TODO: Copy attribute node too
   if (node_->type != XML_ELEMENT_NODE)
     return;
   xmlDocPtr doc = xmlNewDoc((const xmlChar*)"1.0");
   if (doc == NULL)
     return;
   new_node.node_ = xmlDocCopyNode(node_, doc, 1);
   if (new_node.node_ == NULL)
     return;
   xmlDocSetRootElement(doc, new_node.node_);
   new_node.is_owner_ = true;
   return;
 }
Esempio n. 30
0
char * xml_node_to_str(struct xml_node_ctx *ctx, xml_node_t *node)
{
	xmlChar *buf;
	int bufsiz;
	char *ret, *pos;
	xmlNodePtr n = (xmlNodePtr) node;
	xmlDocPtr doc;

	doc = xmlNewDoc((xmlChar *) "1.0");
	n = xmlDocCopyNode(n, doc, 1);
	xmlDocSetRootElement(doc, n);
	xmlDocDumpFormatMemory(doc, &buf, &bufsiz, 0);
	xmlFreeDoc(doc);
	if (!buf)
		return NULL;
	pos = (char *) buf;
	if (strncmp(pos, "<?xml", 5) == 0) {
		pos = strchr(pos, '>');
		if (pos)
			pos++;
		while (pos && (*pos == '\r' || *pos == '\n'))
			pos++;
	}
	if (pos)
		ret = os_strdup(pos);
	else
		ret = NULL;
	xmlFree(buf);

	if (ret) {
		pos = ret;
		if (pos[0]) {
			while (pos[1])
				pos++;
		}
		while (pos >= ret && *pos == '\n')
			*pos-- = '\0';
	}

	return ret;
}