Ejemplo n.º 1
0
bool CXMLElement::MoveElement(CXMLElement* p_element, bool p_sibling, bool p_before)
{
	xmlNodePtr t_parent;
	for(t_parent = element; t_parent != NULL; t_parent = t_parent -> parent)
		if (t_parent == p_element -> GetNodePtr())
			return false;

	xmlUnlinkNode(p_element -> GetNodePtr());
	if (p_sibling)
	{
		if (p_before)
			xmlAddPrevSibling(element, p_element -> GetNodePtr());
		else
			xmlAddNextSibling(element, p_element -> GetNodePtr());
	}
	else
	{
		if (p_before && element -> children != NULL)
			xmlAddPrevSibling(element -> children, p_element -> GetNodePtr());
		else
			xmlAddChild(element, p_element -> GetNodePtr());
	}

	return true;
}
Ejemplo n.º 2
0
/**
 * Creates a new element node and sets it as the root element. This will
 * only work if the document is empty; otherwise EDocumentNotEmpty is thrown.
 */
ElementNode* Document::createRootElement(const char *pcszRootElementName,
        const char *pcszComment /* = NULL */)
{
    if (m->pRootElement || m->plibDocument)
        throw EDocumentNotEmpty(RT_SRC_POS);

    // libxml side: create document, create root node
    m->plibDocument = xmlNewDoc((const xmlChar*)"1.0");
    xmlNode *plibRootNode;
    if (!(plibRootNode = xmlNewNode(NULL,        // namespace
                                    (const xmlChar*)pcszRootElementName)))
        throw std::bad_alloc();
    xmlDocSetRootElement(m->plibDocument, plibRootNode);
    // now wrap this in C++
    m->pRootElement = new ElementNode(NULL, NULL, plibRootNode);

    // add document global comment if specified
    if (pcszComment != NULL)
    {
        xmlNode *pComment;
        if (!(pComment = xmlNewDocComment(m->plibDocument,
                                          (const xmlChar *)pcszComment)))
            throw std::bad_alloc();
        xmlAddPrevSibling(plibRootNode, pComment);
        // now wrap this in C++
        m->pComment = new ElementNode(NULL, NULL, pComment);
    }

    return m->pRootElement;
}
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
0
 XMLNode XMLNode::NewChild(const char *name, int n, bool global_order) {
   if (node_ == NULL)
     return XMLNode();
   if (node_->type != XML_ELEMENT_NODE)
     return XMLNode();
   const char *name_ = strchr(name, ':');
   xmlNsPtr ns = NULL;
   if (name_ != NULL) {
     std::string ns_(name, name_ - name);
     ns = xmlSearchNs(node_->doc, node_, (const xmlChar*)(ns_.c_str()));
     ++name_;
   }
   else
     name_ = name;
   xmlNodePtr new_node = xmlNewNode(ns, (const xmlChar*)name_);
   if (new_node == NULL)
     return XMLNode();
   if (n < 0)
     return XMLNode(xmlAddChild(node_, new_node));
   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));
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
WsXmlNodeH
xml_parser_node_add(WsXmlNodeH base,
		int where,
		const char *nsUri,
		const char *localName, const char *value, int xmlescape)
{
	xmlNodePtr xmlBase = (xmlNodePtr) base;
	xmlNodePtr newNode =
		make_new_xml_node((where != XML_ELEMENT_NEXT &&
					where != XML_ELEMENT_PREV)
				? xmlBase : xmlBase->parent, nsUri,
				localName, value, xmlescape);
	if (newNode) {
		switch (where) {
		case XML_ELEMENT_NEXT:
			xmlAddNextSibling((xmlNodePtr) base, newNode);
			break;
		case XML_ELEMENT_PREV:
			xmlAddPrevSibling((xmlNodePtr) base, newNode);
			break;
		case XML_LAST_CHILD:
		default:
			xmlAddChild((xmlNodePtr) base, newNode);
			break;
		}
	}
	return (WsXmlNodeH) newNode;

}
Ejemplo n.º 7
0
Bool CXMLDocument::AddDTD(char *data, unsigned long tlength)
{
	if (!isinited()) return False;
	xmlParserInputBufferPtr dtdInputBufferPtr; 
	xmlDtdPtr dtd; 
	dtdInputBufferPtr = xmlParserInputBufferCreateMem(data, tlength, XML_CHAR_ENCODING_UTF8); 
	dtd = xmlIOParseDTD(NULL, dtdInputBufferPtr, XML_CHAR_ENCODING_UTF8); 
	if (!dtd) return False;
	if (dtd->name != NULL)
		xmlFree((char*)dtd->name);
	CXMLElement telement;
	GetRootElement(&telement);
	dtd->name = xmlStrdup((xmlChar *)telement.GetName());
	doc->intSubset = dtd;
    if (dtd->ExternalID != NULL) { 
           xmlFree((xmlChar *) dtd->ExternalID); 
           dtd->ExternalID = NULL; 
       } 
       if (dtd->SystemID != NULL) { 
           xmlFree((xmlChar *) dtd->SystemID); 
           dtd->SystemID = NULL; 
       } 
	dtd->doc = doc;
	dtd->parent = doc;
	if (doc->children == NULL) xmlAddChild((xmlNodePtr)doc, (xmlNodePtr)dtd);
	else xmlAddPrevSibling(doc->children, (xmlNodePtr)dtd);
	return Validate();
}
Ejemplo n.º 8
0
/*
 * Interprets nodes from @topnode and for all of @topnode's next siblings 
 */
static gboolean
real_run_at_node (GdaReportEngine *engine, xmlNodePtr topnode, RunContext *context, GError **error)
{
	xmlNodePtr node;
	xmlNodePtr next_node = NULL;
	for (node = topnode; node; node = next_node) {
		next_node = node->next;

		if (!strncmp ((gchar *) node->name, "gda_report", 10)) {
			GSList *created_nodes = NULL;
			gboolean cmd_res = TRUE;
			gsize i;
			gboolean command_found = FALSE;
			
			for (i = 0; i < sizeof (commands) / sizeof (EngineCommand); i++) {
				EngineCommand *ec = (EngineCommand *) &(commands [i]);
				if (ec->has_prefix) {
					if (!strcmp (((gchar *) node->name) + 10, ec->tag_name + 10)) {
						command_found = TRUE;
						if (ec->func)
							cmd_res = (ec->func) (engine, node, &created_nodes, context, error);
						break;
					}
				}
			}
			if (!command_found) {
				/* gda_ node not implemented */
				TO_IMPLEMENT;
				g_warning ("Engine command '%s' is not yet implemented", (gchar *) node->name);
			}

			if (created_nodes) {
				/* put @node's contents before @node */
				GSList *list;
				for (list = created_nodes; list; list = list->next) {
					next_node = xmlAddPrevSibling (node, (xmlNodePtr) list->data);
					g_assert (next_node);
				}
				g_slist_free (created_nodes);

				/* destroy @node */
				xmlUnlinkNode (node);
				xmlFreeNode (node);
				next_node = next_node->next;
			} 
			else {
				/* destroy @node */
				xmlUnlinkNode (node);
				xmlFreeNode (node);
			}
			if (!cmd_res)
				return FALSE;
		}
		else if (node->children) {
			if (!real_run_at_node (engine, node->children, context, error))
				return FALSE;
		}
	}
	return TRUE;
}
Ejemplo n.º 9
0
void Document::importDocument(Document& other, Node& importNode)
{
	std::lock_guard<std::mutex> lock(_lock);

	// Locate the top-level node(s) of the other document
	xml::NodeList topLevelNodes = other.findXPath("/*");

	xmlNodePtr targetNode = importNode.getNodePtr();

	if (targetNode->name == NULL)
	{
		// invalid importnode
		return;
	}

	// greebo: Not all target nodes already have a valid child node, use a modified algorithm
	// to handle that situation as suggested by malex984

	// Add each of the imported nodes to the target importNode
	for (std::size_t i = 0; i < topLevelNodes.size(); ++i)
	{
		if (targetNode->children == NULL)
		{
			xmlUnlinkNode(topLevelNodes[i].getNodePtr());
			xmlAddChild(targetNode, topLevelNodes[i].getNodePtr());
		}
		else
		{
			xmlAddPrevSibling(targetNode->children, topLevelNodes[i].getNodePtr());
		}
	}
}
Ejemplo n.º 10
0
// Node replaceChild(in Node newChild,in Node oldChild) raises(DOMException);
static void _replaceChild(Request& r, MethodParams& params) {
	xmlNode& newChild=as_node(params, 0, "newChild must be node");
	xmlNode& oldChild=as_node(params, 1, "oldChild must be node");

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

	if(newChild.doc!=&xmldoc)
		throw Exception("xml.dom",
			0,
			"WRONG_DOCUMENT_ERR");
	if(oldChild.doc!=&xmldoc)
		throw Exception("xml.dom",
			0,
			"WRONG_DOCUMENT_ERR");

	if(oldChild.parent!=&selfNode)
		throw Exception("xml.dom",
			0,
			"NOT_FOUND_ERR");

	xmlNode* refChild=oldChild.next;
	xmlUnlinkNode(&oldChild);
	xmlNode* retNode;
	if(refChild)
		retNode=xmlAddPrevSibling(refChild, &newChild);
	else
		retNode=xmlAddChild(&selfNode, &newChild);

	// write out result
	writeNode(r, vxdoc, retNode);
}
Ejemplo n.º 11
0
void Node::InsertBefore(std::shared_ptr<Node> child)
{
    xmlNodePtr newNode = xmlAddPrevSibling(xml(), child->xml());
    if ( newNode == nullptr )
        throw InternalError("Unable to add child node", xmlGetLastError());
    child->rebind(newNode);
}
Ejemplo n.º 12
0
static BOOL link_datatypes(xmlDocPtr schema)
{
    xmlNodePtr root, next, child;
    xmlNsPtr ns;

    assert(xmlGetExternalEntityLoader() == external_entity_loader);
    root = xmlDocGetRootElement(schema);
    if (!root)
        return FALSE;

    for (ns = root->nsDef; ns != NULL; ns = ns->next)
    {
        if (xmlStrEqual(ns->href, DT_nsURI))
            break;
    }

    if (!ns)
        return FALSE;

    next = xmlFirstElementChild(root);
    child = xmlNewChild(root, NULL, BAD_CAST "import", NULL);
    if (next) child = xmlAddPrevSibling(next, child);
    xmlSetProp(child, BAD_CAST "namespace", DT_nsURI);
    xmlSetProp(child, BAD_CAST "schemaLocation", DT_nsURI);

    return TRUE;
}
Ejemplo n.º 13
0
bool CSpmXml::AddNode(xmlNodePtr pNode, xmlNodePtr pContext, char nContext)
{
	if (0 == pNode)
		return false;

	pContext = GetNode(pContext);
	if (0 == pContext)
		return false;

	xmlNodePtr pCurNode = 0;
	switch (nContext)
	{
	case SPM_XML_CHILD:
		pCurNode = xmlAddChild(pContext, pNode);
		break;

	case SPM_XML_NEXT_SIBLING:
		pCurNode = xmlAddNextSibling(pContext, pNode);
		break;

	case SPM_XML_PREV_SIBLING:
		pCurNode = xmlAddPrevSibling(pContext, pNode);
		break;

	default:
		return false;
	}

	if (0 == pCurNode)
		return false;

	m_pCurNode = pCurNode;
	SetModified();
	return true;
}
Ejemplo n.º 14
0
/**
 *  'insert' operation
 */
static void
edInsert(xmlDocPtr doc, xmlNodeSetPtr nodes, const char *val, const char *name,
         XmlNodeType type, int mode)
{
    int i;

    xmlXPathEmptyNodeSet(previous_insertion);

    for (i = 0; i < nodes->nodeNr; i++)
    {
        xmlNodePtr node;

        if (nodes->nodeTab[i] == (void*) doc && mode != 0) {
            fprintf(stderr, "The document node cannot have siblings.\n");
            exit(EXIT_INTERNAL_ERROR);
        }

        /* update node */
        if (type == XML_ATTR)
        {
            node = (xmlNodePtr) xmlNewProp(nodes->nodeTab[i], BAD_CAST name, BAD_CAST val);
        }
        else if (type == XML_ELEM)
        {
            node = xmlNewDocNode(doc, NULL /* TODO: NS */, BAD_CAST name, BAD_CAST val);
            if (mode > 0)
                xmlAddNextSibling(nodes->nodeTab[i], node);
            else if (mode < 0)
                xmlAddPrevSibling(nodes->nodeTab[i], node);
            else
                xmlAddChild(nodes->nodeTab[i], node);
        }
        else if (type == XML_TEXT)
        {
            node = xmlNewDocText(doc, BAD_CAST val);
            if (mode > 0)
                xmlAddNextSibling(nodes->nodeTab[i], node);
            else if (mode < 0)
                xmlAddPrevSibling(nodes->nodeTab[i], node);
            else
                xmlAddChild(nodes->nodeTab[i], node);
        }
        xmlXPathNodeSetAdd(previous_insertion, node);
    }
}
Ejemplo n.º 15
0
// Inherits XMLSpy generation source function.
xmlNodePtr CNode::InternalInsertNodeAt(const tstring& sNamespaceURI, const tstring& sName, int nIndex, CNode& rNode)
{
	rNode.m_pDOMNode = xmlAddPrevSibling(
			InternalGetAt(Element, sNamespaceURI, sName, nIndex),
			xmlCopyNode(rNode.m_pDOMNode, 1)
			);

	return rNode.m_pDOMNode;
}
Ejemplo n.º 16
0
/*
 * Handles incomplete html fragments as may occur on the clipboard,
 * e.g. a <td> without <tr> and <table> in front of it.
 */
static void
html_search_for_tables (htmlNodePtr cur, htmlDocPtr doc,
			WorkbookView *wb_view, GnmHtmlTableCtxt *tc)
{
	htmlNodePtr ptr;

	if (cur == NULL) {
		xmlGenericError(xmlGenericErrorContext,
				"htmlNodeDumpFormatOutput : node == NULL\n");
		return;
	}

	if (cur->type != XML_ELEMENT_NODE)
		return;

	if (xmlStrEqual (cur->name, CC2XML ("table"))) {
		html_read_table (cur, doc, wb_view, tc);
	} else if (starts_inferred_table (cur) || starts_inferred_row (cur)) {
		htmlNodePtr tnode = xmlNewNode (NULL, "table");

		/* Link in a table node */
		xmlAddPrevSibling (cur, tnode);
		if (starts_inferred_row (cur)) {
			htmlNodePtr rnode = xmlNewNode (NULL, "tr");

			/* Link in a row node */
			xmlAddChild (tnode, rnode);
			/* Make following elements children of the row node,
			 * until we meet one which isn't legal in a row. */
			while ((ptr = tnode->next) != NULL) {
				if (ends_inferred_row (ptr))
					break;
				xmlUnlinkNode (ptr);
				xmlAddChild (rnode, ptr);
			}
		}
		/* Make following elements children of the row node,
		 * until we meet one which isn't legal in a table. */
		while ((ptr = tnode->next) != NULL) {
			if (ends_inferred_table (ptr))
				break;
			xmlUnlinkNode (ptr);
			xmlAddChild (tnode, ptr);
		}
		html_read_table (tnode, doc, wb_view, tc);
	} else {
		for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) {
			html_search_for_tables (ptr, doc, wb_view, tc);
			/* ptr may now have been pushed down in the tree,
			 * if so, ptr->next is not the right pointer to
			 * follow */
			while (ptr->parent != cur)
				ptr = ptr->parent;
		}
	}
}
Ejemplo n.º 17
0
/*
 * Class:     org_xmlsoft_Node
 * Method:    addPrevSiblingImpl
 * Signature: (Lrath/libxml/Node;)Lrath/libxml/Node;
 */
JNIEXPORT jobject JNICALL Java_org_xmlsoft_Node_addPrevSiblingImpl
(JNIEnv *env, jobject obj, jobject toAdd) {
    xmlNode *node = findNode(env, obj);
    xmlNode *nodeToAdd = findNode(env, toAdd);
    jobject jdoc = (*env)->GetObjectField(env, obj, fieldNodeDocument);
    xmlNode *nodeAdded = xmlAddPrevSibling(node, nodeToAdd);
    jobject ret = buildNode(env, nodeAdded, jdoc);
    (*env)->DeleteLocalRef(env, jdoc);
    return ret;
}
Ejemplo n.º 18
0
// Inherits XMLSpy generation source function.
xmlNodePtr CNode::InternalInsertAt(ENodeType eNodeType, const tstring& sNamespaceURI, const tstring& sName, int nIndex, const tstring& sValue)
{
	if (eNodeType == Element)
		return xmlAddPrevSibling(
				InternalGetAt(eNodeType, sNamespaceURI, sName, nIndex),
				InternalCreate(eNodeType, sNamespaceURI, sName, sValue)
				);
	else
		return InternalAppend(eNodeType, sNamespaceURI, sName, sValue);
}
Ejemplo n.º 19
0
    void XMLNodeList::insertAtBeginning(const XMLElement & elem)
    {
        xmlNode *cpy = xmlCopyNode(elem.getRealNode(), 1);

        xmlUnlinkNode(cpy);
        scope->unregisterNodeListPointer(parent->children);
        xmlAddPrevSibling(parent->children, cpy);
        scope->registerPointers(parent->children, this);
        size++;
    }
Ejemplo n.º 20
0
/*
 * call-seq:
 *  add_previous_sibling(node)
 *
 * Insert +node+ before this node (as a sibling).
 */
static VALUE add_previous_sibling(VALUE self, VALUE rb_node)
{
  xmlNodePtr node, new_sibling;
  Data_Get_Struct(self, xmlNode, node);
  Data_Get_Struct(rb_node, xmlNode, new_sibling);
  xmlAddPrevSibling(node, new_sibling);

  rb_funcall(rb_node, rb_intern("decorate!"), 0);

  return rb_node;
}
Ejemplo n.º 21
0
std::shared_ptr<Element> Node::InsertBefore(const string &name, const string & prefix)
{
    xmlNodePtr child = createChild(name, prefix);
    xmlNodePtr newNode = xmlAddPrevSibling(xml(), child);
    if ( newNode == nullptr )
    {
        xmlFreeNode(child);
        throw InternalError(std::string("Could not add child element node named '") + name.c_str() + "'", xmlGetLastError());
    }
    
    return Wrapped<Element, _xmlNode>(newNode);
}
void 
savePostXml(char *filename, wppost_t *post) {
	char xmlfilepath[300];
	char dirpath[300];
	char *subject;
	xmlDocPtr doc = xmlParseFile(filename);
	xmlNodePtr urlNode = getNodeByXpath(doc, (xmlChar *) "/post/url");
	xmlNodePtr postIdNode = xmlNewNode (NULL, BAD_CAST "postid");
	xmlNodePtr blogIdNode = xmlNewNode (NULL, BAD_CAST "blogid");
	xmlNodeSetContent(postIdNode, (xmlChar *) post->postid);
	xmlNodeSetContent(blogIdNode, (xmlChar *) post->blogid);
	xmlAddPrevSibling(urlNode, blogIdNode);
	xmlAddPrevSibling(urlNode, postIdNode);
	sprintf(dirpath, "%s/%s", getenv("HOME"), WPRESSPATH); 
	mkdir(dirpath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
	subject = clean_string(post->subject);
	sprintf(xmlfilepath, "%s/post-%s-%s.xml", dirpath, post->postid, subject); 
	free(subject);
	xmlSaveFormatFileEnc(xmlfilepath, doc, "UTF-8", 1);
	printf("Saved as %s\n", xmlfilepath);
	xmlFreeDoc(doc);
}
Ejemplo n.º 23
0
// Node insertBefore(in Node newChild,in Node refChild) raises(DOMException);
static void _insertBefore(Request& r, MethodParams& params) {
	xmlNode& newChild=as_node(params, 0, "newChild must be node");
	xmlNode& refChild=as_node(params, 1, "refChild must be node");

	VXnode& vnode=GET_SELF(r, VXnode);
	VXdoc& vxdoc=vnode.get_vxdoc();

	//xmlNode& selfNode=vnode.get_xmlnode();
	
	xmlNode* retNode=xmlAddPrevSibling(&refChild, &newChild);
	// write out result
	writeNode(r, vxdoc, retNode);
}
Ejemplo n.º 24
0
Archivo: xml.c Proyecto: archi-tekt/cpm
/* #############################################################################
 *
 * Description    add a DTD to the xml document
 * Author         Harry Brueckner
 * Date           2005-05-04
 * Arguments      SHOWERROR_FN - callback function for error messages
 * Return         -1 if the DTD could not be updated, 0 if the document did not
 *                validate and 1 if everything is ok
 */
int checkDtd(SHOWERROR_FN showerror_cb)
  {
    xmlDtd*             dtd;
    xmlParserInputBuffer*   inputbuffer;
    xmlValidCtxt*       context = xmlNewValidCtxt();
    char*               dtdbuffer;

    TRACE(99, "checkDtd()", NULL);

    if (!xmldoc)
      { return -1; }

    xmlRemoveDtd();

    /* first we create the DTD as a whole */
    dtdbuffer = memAlloc(__FILE__, __LINE__,
        strlen(dtd_1) + strlen(dtd_2) + strlen(dtd_3) + 1);
    if (!dtdbuffer)
      { return -1; }

    strStrncpy(dtdbuffer, dtd_1, strlen(dtd_1) + 1);
    strStrncat(dtdbuffer, dtd_2, strlen(dtd_2) + 1);
    strStrncat(dtdbuffer, dtd_3, strlen(dtd_3) + 1);

    /* create the xml buffer */
    inputbuffer = xmlParserInputBufferCreateMem(dtdbuffer, strlen(dtdbuffer),
        XML_CHAR_ENCODING_8859_1);
    memFreeString(__FILE__, __LINE__, dtdbuffer);
    if (!dtdbuffer)
      { return -1; }

    /* and finally create the DTD */
    dtd = xmlIOParseDTD(NULL, inputbuffer, XML_CHAR_ENCODING_8859_1);

    if (!dtd)
      { return -1; }

    /* and attach the DTD to the document */
    if (!xmldoc -> children)
      { xmlAddChild((xmlNode*)xmldoc, (xmlNode*)dtd); }
    else
      { xmlAddPrevSibling(xmldoc -> children, (xmlNode*)dtd); }

    /* we set our own error handler */
    validateShowError = showerror_cb;
    context -> error = xmlValidateError;
    context -> warning = xmlValidateWarning;

    return xmlValidateDtd(context, xmldoc, dtd);
  }
Ejemplo n.º 25
0
static void
ngx_http_xslt_sax_external_subset(void *data, const xmlChar *name,
    const xmlChar *externalId, const xmlChar *systemId)
{
    xmlParserCtxtPtr ctxt = data;

    xmlDocPtr                         doc;
    xmlDtdPtr                         dtd;
    ngx_http_request_t               *r;
    ngx_http_xslt_filter_ctx_t       *ctx;
    ngx_http_xslt_filter_loc_conf_t  *conf;

    ctx = ctxt->sax->_private;
    r = ctx->request;

    conf = ngx_http_get_module_loc_conf(r, ngx_http_xslt_filter_module);

    ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "xslt filter extSubset: \"%s\" \"%s\" \"%s\"",
                   name ? name : (xmlChar *) "",
                   externalId ? externalId : (xmlChar *) "",
                   systemId ? systemId : (xmlChar *) "");

    doc = ctxt->myDoc;

#if (NGX_HTTP_XSLT_REUSE_DTD)

    dtd = conf->dtd;

#else

    dtd = xmlCopyDtd(conf->dtd);
    if (dtd == NULL) {
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                      "xmlCopyDtd() failed");
        return;
    }

    if (doc->children == NULL) {
        xmlAddChild((xmlNodePtr) doc, (xmlNodePtr) dtd);

    } else {
        xmlAddPrevSibling(doc->children, (xmlNodePtr) dtd);
    }

#endif

    doc->extSubset = dtd;
}
Ejemplo n.º 26
0
/*AddChild - creates new child element
tname - name of new child element
tcontent - value of new child element
telement - on success, points to new child element
returns False on error.
*/
Bool CXMLElement::AddChild(char *tname, char *tcontent,CXMLElement *telement, bool tbefore)
{
		if (!isinited()) return False;
	   xmlNodePtr newchild = xmlNewTextChild(element, NULL, (xmlChar *)tname, 
		   (xmlChar *)tcontent);
	   if (newchild)
		 {
			 if (tbefore)
			   xmlAddPrevSibling(element -> children, newchild);
				 
		   if (telement) 
			   telement->SetNodePtr(newchild);
		 }
	   return newchild != NULL;
}
Ejemplo n.º 27
0
// Inherits XMLSpy generation source function.
void CNode::InternalSetElementValue(const tstring& sValue)
{
	xmlNodePtr pTextNode = xmlNewDocText(m_pDOMNode->doc, X(sValue));
	xmlNodePtr pChild = m_pDOMNode->children;
	if(pChild) {
		if(pChild->type == XML_TEXT_NODE) {
			xmlReplaceNode(pChild, pTextNode);
			xmlFreeNode(pChild);
		} else {
			xmlAddPrevSibling(pChild, pTextNode);
		}
	} else {
		xmlAddChild(m_pDOMNode, pTextNode);
	}
}
Ejemplo n.º 28
0
/*
 * call-seq:
 *    node.prev = node
 *
 * Insert the specified node as this node's previous sibling.
 */
static VALUE rxml_node_prev_set(VALUE self, VALUE rnode)
{
  xmlNodePtr cnode, pnode, ret;

  if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
    rb_raise(rb_eTypeError, "Must pass an XML::Node object");

  Data_Get_Struct(self, xmlNode, pnode);
  Data_Get_Struct(rnode, xmlNode, cnode);

  ret = xmlAddPrevSibling(pnode, cnode);
  if (ret == NULL)
    rxml_raise(&xmlLastError);

  return (rxml_node_wrap(cXMLNode, ret));
}
Ejemplo n.º 29
0
int main() {
    xmlDocPtr doc;
    xmlNodePtr racine, premier_prod, nouv_prod;

    // Ouverture du fichier XML
    xmlKeepBlanksDefault(0);
    doc = xmlParseFile("catalogue.xml");
    if (doc == NULL) {
        fprintf(stderr, "Document XML invalide\n");
        return EXIT_FAILURE;
    }
    // Récupération de la racine
    racine = xmlDocGetRootElement(doc);
    if (racine == NULL) {
        fprintf(stderr, "Document XML vierge\n");
        xmlFreeDoc(doc);
        return EXIT_FAILURE;
    }
    // Récupération du premier produit
    premier_prod = obtenir_premier_produit(doc);
    if (premier_prod == NULL) {
        fprintf(stderr, "Impossible de trouver le premier produit\n");
        xmlFreeDoc(doc);
        return EXIT_FAILURE;
    }
    // Ajout d'un nouveau produit avant le premier produit (en tête)
    nouv_prod = creer_produit("CD0YAH", "Autocollant Developpez.com", "0.80");
    if (nouv_prod) {
        xmlAddPrevSibling(premier_prod, nouv_prod);
    }
    // Ajout d'un nouveau produit après le premier produit
    nouv_prod = creer_produit("U0TZ6K", "Lot de 10 autocollants Developpez.com", "5.00");
    if (nouv_prod) {
        xmlAddNextSibling(premier_prod, nouv_prod);
    }
    // Ajout d'un nouveau produit en fin/queue
    nouv_prod = creer_produit("ZQEYAN", "Mug Developpez.com", "4.00");
    if (nouv_prod) {
        xmlAddSibling(premier_prod, nouv_prod);
    }
    // Affichage de l'arbre DOM tel qu'il est en mémoire
    xmlDocFormatDump(stdout, doc, 1);
    // Libération de la mémoire
    xmlFreeDoc(doc);

    return EXIT_SUCCESS;
}
Ejemplo n.º 30
0
void Document::importDocument(Document& other, Node& importNode) {
	// Locate the top-level node(s) of the other document
	xml::NodeList topLevelNodes = other.findXPath("/*");
	
	xmlNodePtr targetNode = importNode.getNodePtr();

	if (targetNode->children == NULL || targetNode->name == NULL) {
		// invalid importnode
		return;
	}

	// Add each of the imported nodes to the target importNode
	for (std::size_t i = 0; i < topLevelNodes.size(); i++) {
		xmlAddPrevSibling(targetNode->children, 
						  topLevelNodes[i].getNodePtr());
	}
}