예제 #1
0
파일: node.c 프로젝트: RareHare/reactos
HRESULT node_clone(xmlnode *This, VARIANT_BOOL deep, IXMLDOMNode **cloneNode)
{
    IXMLDOMNode *node;
    xmlNodePtr clone;

    if(!cloneNode) return E_INVALIDARG;

    clone = xmlCopyNode(This->node, deep ? 1 : 2);
    if (clone)
    {
        xmlSetTreeDoc(clone, This->node->doc);
        xmldoc_add_orphan(clone->doc, clone);

        node = create_node(clone);
        if (!node)
        {
            ERR("Copy failed\n");
            xmldoc_remove_orphan(clone->doc, clone);
            xmlFreeNode(clone);
            return E_FAIL;
        }

        *cloneNode = node;
    }
    else
    {
        ERR("Copy failed\n");
        return E_FAIL;
    }

    return S_OK;
}
예제 #2
0
static VALUE rxml_node_remove_ex(VALUE self)
{
  xmlNodePtr xnode;
  Data_Get_Struct(self, xmlNode, xnode);
  /* Unlink the node from its parent. */
  xmlUnlinkNode(xnode);
  /* Now set the nodes parent to nil so it can
   be freed if the reference to it goes out of scope*/
  xmlSetTreeDoc(xnode, NULL);

  /* Now return the removed node so the user can
   do something wiht it.*/
  return self;
}
예제 #3
0
xmlNodePtr generation_callback(void * handle, xmlNodePtr node, void* ctxt) {
    printf("\noooooooooooo %s: %p\n", __FUNCTION__, handle);

    xmlSetTreeDoc(node, (xmlDocPtr)ctxt);
    if (xmlStrEqual(node->name, BAD_CAST "people"))
	xmlDocSetRootElement(node->doc, node);

    dump_doc(node->doc, node);

    if (xmlStrEqual(node->name, BAD_CAST "fname")) {
	printf("here!\n");
	return (xmlNodePtr) xmlNewNsProp(node->parent, node->ns, node->name, BAD_CAST "bob");
    }
    return node;
}
예제 #4
0
파일: node.c 프로젝트: IMSoP/php-src
static xmlNodePtr _php_dom_insert_fragment(xmlNodePtr nodep, xmlNodePtr prevsib, xmlNodePtr nextsib, xmlNodePtr fragment, dom_object *intern, dom_object *childobj) /* {{{ */
{
	xmlNodePtr newchild, node;

	newchild = fragment->children;

	if (newchild) {
		if (prevsib == NULL) {
			nodep->children = newchild;
		} else {
			prevsib->next = newchild;
		}
		newchild->prev = prevsib;
		if (nextsib == NULL) {
			nodep->last = fragment->last;
		} else {
			fragment->last->next = nextsib;
			nextsib->prev = fragment->last;
		}

		node = newchild;
		while (node != NULL) {
			node->parent = nodep;
			if (node->doc != nodep->doc) {
				xmlSetTreeDoc(node, nodep->doc);
				if (node->_private != NULL) {
					childobj = node->_private;
					childobj->document = intern->document;
					php_libxml_increment_doc_ref((php_libxml_node_object *)childobj, NULL);
				}
			}
			if (node == fragment->last) {
				break;
			}
			node = node->next;
		}

		fragment->children = NULL;
		fragment->last = NULL;
	}

	return newchild;
}
예제 #5
0
/*
 * call-seq:
 *    XML::Dtd.new("DTD string") -> dtd
 *    XML::Dtd.new("public", "system") -> dtd
 *    XML::Dtd.new("name", "public", "system", document) -> external subset dtd
 *    XML::Dtd.new("name", "public", "system", document, false) -> internal subset dtd
 *    XML::Dtd.new("name", "public", "system", document, true) -> internal subset dtd
 *
 * Create a new Dtd from the specified public and system
 * identifiers.
 */
static VALUE rxml_dtd_initialize(int argc, VALUE *argv, VALUE self)
{
  VALUE external, system, dtd_string;
  xmlParserInputBufferPtr buffer;
  xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
  xmlChar *new_string;
  xmlDtdPtr xdtd;

  // 1 argument -- string                            --> parsujeme jako dtd
  // 2 arguments -- public, system                   --> bude se hledat
  // 3 arguments -- public, system, name             --> creates an external subset (any parameter may be nil)
  // 4 arguments -- public, system, name, doc        --> creates an external subset (any parameter may be nil)
  // 5 arguments -- public, system, name, doc, true  --> creates an internal subset (all but last parameter may be nil)
  switch (argc)
  {
  case 3:
  case 4:
  case 5: {
      VALUE name, doc, internal;
      const xmlChar *xname = NULL, *xpublic = NULL, *xsystem = NULL;
      xmlDocPtr xdoc = NULL;

      rb_scan_args(argc, argv, "32", &external, &system, &name, &doc, &internal);

      if (external != Qnil) {
        Check_Type(external, T_STRING);
        xpublic = (const xmlChar*) StringValuePtr(external);
      }
      if (system != Qnil) {
        Check_Type(system, T_STRING);
        xsystem = (const xmlChar*) StringValuePtr(system);
      }
      if (name != Qnil) {
        Check_Type(name, T_STRING);
        xname = (const xmlChar*) StringValuePtr(name);
      }
      if (doc != Qnil) {
        if (rb_obj_is_kind_of(doc, cXMLDocument) == Qfalse)
          rb_raise(rb_eTypeError, "Must pass an XML::Document object");
        Data_Get_Struct(doc, xmlDoc, xdoc);
      }

      if (internal == Qnil || internal == Qfalse)
        xdtd = xmlNewDtd(xdoc, xname, xpublic, xsystem);
      else
        xdtd = xmlCreateIntSubset(xdoc, xname, xpublic, xsystem);

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

      /* Document will free this dtd now. */
      RDATA(self)->dfree = NULL;
      DATA_PTR(self) = xdtd;

      xmlSetTreeDoc((xmlNodePtr) xdtd, xdoc);
    }
    break;

  case 2:
    rb_scan_args(argc, argv, "20", &external, &system);

    Check_Type(external, T_STRING);
    Check_Type(system, T_STRING);

    xdtd = xmlParseDTD((xmlChar*) StringValuePtr(external),
        (xmlChar*) StringValuePtr(system));

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

    DATA_PTR(self) = xdtd;

    xmlSetTreeDoc((xmlNodePtr) xdtd, NULL);
    break;

  case 1:
    rb_scan_args(argc, argv, "10", &dtd_string);
    Check_Type(dtd_string, T_STRING);

    /* Note that buffer is freed by xmlParserInputBufferPush*/
    buffer = xmlAllocParserInputBuffer(enc);
    new_string = xmlStrdup((xmlChar*) StringValuePtr(dtd_string));
    xmlParserInputBufferPush(buffer, xmlStrlen(new_string),
        (const char*) new_string);

    xdtd = xmlIOParseDTD(NULL, buffer, enc);

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

    xmlFree(new_string);

    DATA_PTR(self) = xdtd;
    break;

  default:
    rb_raise(rb_eArgError, "wrong number of arguments");
  }

  return self;
}