示例#1
0
    void XMLNodeList::replaceAtIndex(int index, const XMLElement & elem)
    {
        xmlNode *n = getListNode(index);

        if (n && n != elem.getRealNode())
        {
            if (index == 1)
            {
                scope->unregisterNodeListPointer(parent->children);
            }
            xmlNode *previous = n->prev;
            xmlNode *next = n->next;
            xmlNode *cpy = xmlCopyNode(elem.getRealNode(), 1);

            xmlUnlinkNode(cpy);
            xmlReplaceNode(n, cpy);
            xmlFreeNode(n);
            prevNode = cpy;
            cpy->prev = previous;
            cpy->next = next;
            if (index == 1)
            {
                scope->registerPointers(parent->children, this);
            }
        }
    }
示例#2
0
void RheiaConfigurationManager::Delete()
{
    if( m_root == NULL || m_doc == NULL )
        return;

    RheiaConfigurationPattern * builder = RheiaConfigurationPattern::Get();
    wxString group = RheiaC2U( (const char*) m_root->name );

    xmlNode* docRoot = xmlDocGetRootElement(m_doc);
    xmlNode* child = docRoot->children;

    while( child != NULL )
    {
        wxString cname = RheiaC2U( (const char*) child->name );

        if( cname.IsSameAs( group ) )
        {
            xmlReplaceNode( child , NULL );
            return;
        }

        child = child->next;
    }

    wxCriticalSectionLocker(builder->m_criticalSection);
    RheiaConfigurationManagerMap::iterator it = builder->m_groups.find(group);
    if(it != builder->m_groups.end())
        builder->m_groups.erase(it);

    delete this;
}
示例#3
0
void RheiaConfigurationManager::Write(const wxString& path,  const RheiaStringStringMap& as)
{
    wxString key(path);
    xmlNode* node;
    node = RheiaXmlManager::Get()->AssertPath(key,m_root);
    xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key );

    /* First check if the node exist */
    xmlNode *child = e->children;
    while ( child != NULL )
    {
        wxString ChildName = RheiaC2U( (const char *) child->name );
        xmlNode* sub = child->next;
        if ( ChildName.IsSameAs( wxT("variable") ) )
        {
            xmlReplaceNode( child , NULL );
            child = NULL;
        }
        child = sub;
    }

    RheiaStringStringMap::const_iterator it = as.begin();
    for( ; it != as.end() ; ++it )
    {
        child = xmlNewNode( NULL , (const xmlChar*) "variable" );
        xmlNewChild(child , NULL , (const xmlChar*) "name" , rxU2C(it->first) );
        xmlNewChild(child , NULL , (const xmlChar*) "value" , rxU2C(it->second) );
        xmlAddChild( e , child );
    }
}
示例#4
0
文件: cam_menu.c 项目: suborb/reelvdr
		virtual bool PatchCamFlags(xmlDocPtr doc, const char *uuid, const char *slot, const char *flags) {
			bool uuid_match=false;
			bool flags_set =false;
			xmlNode *node = xmlDocGetRootElement(doc);
			node = node ? node->children : NULL;
			while(node && xmlStrcmp(node->name, (const xmlChar *)"Description"))
				node=node->next;
			node = node ? node->children : NULL;
			while(node) {
				if(node && !xmlStrcmp(node->name, (const xmlChar *)"component")) {
					xmlNode *item = node->children;
					while(item && xmlStrcmp(item->name, (const xmlChar *)"Description")) {
						item = item->next;
					} // while
					xmlChar *about = item ? xmlGetProp(item, (const xmlChar *)"about") : NULL;
					if(about) {
						if (!xmlStrcmp(about, (const xmlChar *)"Platform")) {
							xmlNode *sub = item->children;
							while(sub) {
								if(!xmlStrcmp(sub->name, (const xmlChar *)"UUID")) {
									xmlChar *value=xmlNodeListGetString(doc, sub->children, 1);
									if(value) {
										uuid_match=!xmlStrcmp(value, (const xmlChar *)uuid); 
										xmlFree(value);
									} // if
								} // if
								sub = sub->next;
							} // while
						} else if(!xmlStrcmp(about, (const xmlChar *)"CAM")) {
							xmlNode *sub = item->children;
							while(sub) {
								if(!xmlStrcmp(sub->name, (const xmlChar *)"Slot")) {
									xmlChar *value=xmlNodeListGetString(doc, sub->children, 1);
									if(value) {
										if (!xmlStrcmp(value, (const xmlChar *)slot)) {
											xmlNode *tst = item->children;
											while(tst) {
												if(!xmlStrcmp(tst->name, (const xmlChar *)"Flags")) {
													xmlReplaceNode(tst, xmlNewChild(item, xmlSearchNs(doc, tst, (const xmlChar *)"prf"), (const xmlChar *)"Flags", (const xmlChar *)flags));
													xmlFreeNode(tst);
													flags_set=true;
													tst = NULL;
													continue;
												} // if
												tst = tst->next;
											} // while
										} // if
										xmlFree(value);
									} // if
								} // if
								sub = sub->next;
							} // while
						} // if
						xmlFree(about);
					} // if
				} // if
				node = node->next;
			} // while
			return uuid_match && flags_set;
		}; // PatchCamFlags
示例#5
0
bool RheiaPackageManagedFile::DoWriteToNode( xmlNode* parent )
{
    xmlNode* child = parent->children;

    while( child != NULL )
    {
        wxString cname = RheiaC2U( (const char*) child->name );
        xmlNode* sub = child->next;

        if( cname.IsSameAs( wxT("name") ) || cname.IsSameAs( wxT("path") ) || cname.IsSameAs( wxT("remove") ) )
        {
            xmlReplaceNode(child , NULL);
        }

        child = sub;
    }

    wxString rem = (m_remove ? wxT("true") : wxT("false"));
    xmlNewChild( parent , NULL , (const xmlChar*) "name" , rxU2C(m_name) );
    xmlNewChild( parent , NULL , (const xmlChar*) "path" , rxU2C(m_path) );
    xmlNewChild( parent , NULL , (const xmlChar*) "type" , rxU2C(m_type) );
    xmlNewChild( parent , NULL , (const xmlChar*) "remove" , rxU2C(rem) );

    return true;
}
示例#6
0
bool RheiaPackageInstallInfo::DoWriteToNode( xmlNode* parent )
{
    xmlNode* child = parent->children;
    while( child != NULL )
    {
        wxString cname = RheiaC2U( (const char*) child->name );
        xmlNode* sub = child->next;
        if( cname.IsSameAs( wxT("Files") )
           || cname.IsSameAs( wxT("Libs") ) )
        {
            xmlReplaceNode(child,NULL);
        }

        child = sub;
    }

    if( m_files != NULL )
    {
        child = xmlNewNode(NULL,(const xmlChar*) "Files" );
        m_files->DoWriteToNode(child);
        xmlAddChild(parent,child);
    }

    if( m_libs != NULL )
    {
        child = xmlNewNode(NULL,(const xmlChar*) "Libs" );
        m_libs->DoWriteToNode(child);
        xmlAddChild(parent,child);
    }

    return true;
}
示例#7
0
// below added for xml merge
// removes spaces between # and the text
static int modifytree(xmlNodePtr* ParentPtr, xmlNodePtr sourceNode)
{
	int notfound = -1; //not found
	xmlNodePtr child = (*ParentPtr)->xmlChildrenNode, txt = NULL;
	while (child != NULL)
	{
		if ((xmlStrcmp(child->name, (const xmlChar*)"text")))
		{
			if ((!xmlStrcmp(child->name, sourceNode->name)))
			{
				xmlNodePtr destNode = xmlCopyNode(sourceNode, 1);
				xmlNodePtr old = xmlReplaceNode(child, destNode);
				xmlFreeNode(old);
				notfound = 0;
				break;
			}
		}
		else
		{
			txt = child;
		}
		child = child->next;
	}

	if (notfound == -1)
	{
		xmlAddChild(*ParentPtr, xmlCopyNode(sourceNode, 1));
		xmlAddChild(*ParentPtr, xmlCopyNode(txt, 1));
		logger_remotem("LOAD_CONFIG_FILE: Node not found, adding new node: %s", sourceNode->name);
	}
	return notfound;
}
示例#8
0
void RheiaConfigurationManager::Delete( const wxString& path )
{
    wxString key(path);
    xmlNode* node;
    node = RheiaXmlManager::Get()->AssertPath(key,m_root);
    xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key );
    xmlReplaceNode( e , NULL );
}
示例#9
0
/* :nodoc: */
static VALUE replace(VALUE self, VALUE _new_node)
{
  xmlNodePtr node, new_node;
  Data_Get_Struct(self, xmlNode, node);
  Data_Get_Struct(_new_node, xmlNode, new_node);

  xmlReplaceNode(node, new_node);
  return self ;
}
示例#10
0
/* :nodoc: */
static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr old, xmlNodePtr cur)
{
  xmlNodePtr retval ;
  retval = xmlReplaceNode(old, cur) ;
  if (retval == old) {
    return cur ; // return semantics for reparent_node_with
  }
  return retval ;
}
示例#11
0
// Inherits XMLSpy generation source function.
xmlNodePtr CNode::InternalReplaceAt(ENodeType eNodeType, const tstring& sNamespaceURI, const tstring& sName, int nIndex, const tstring& sValue)
{
	if (eNodeType == Element)
		return xmlReplaceNode(
				InternalGetAt(eNodeType, sNamespaceURI, sName, nIndex),
				InternalCreate(eNodeType, sNamespaceURI, sName, sValue)
				);
	else
		return InternalAppend(eNodeType, sNamespaceURI, sName, sValue);
}
示例#12
0
// Inherits XMLSpy generation source function.
xmlNodePtr CNode::InternalReplaceNodeAt(const tstring& sNamespaceURI, const tstring& sName, int nIndex, CNode& rNode)
{
	xmlNodePtr pOldNode = rNode.m_pDOMNode;
	rNode.m_pDOMNode = xmlReplaceNode(
			InternalGetAt(Element, sNamespaceURI, sName, nIndex),
			xmlCopyNode(rNode.m_pDOMNode, 1)
			);
	CDoc::ReleaseFragment(pOldNode);

	return rNode.m_pDOMNode;
}
示例#13
0
void RheiaConfigurationManager::Clear()
{
    if( m_root == NULL )
        return;

    xmlNode* child = m_root->children;

    while( child != NULL )
    {
        xmlNode* sub = child->next;
        xmlReplaceNode( child , NULL );
        child = sub;
    }
}
示例#14
0
int SXmlNode::SetContentInCData(std::string value)
{
	if (!_node)
		return -1;
	xmlNodePtr new_node=NULL;
	xmlNodePtr new_root_node=xmlNewDocNode(NULL,0, _node->name,(const xmlChar *)"");
	new_node = xmlNewCDataBlock(NULL,(const xmlChar *) (value.c_str()), value.length());
	xmlAddChild(new_root_node,new_node);
	//xmlNodeSetName(new_node, _node->name);
	xmlReplaceNode(_node,new_root_node);
	xmlFreeNode(_node);	
	_node=new_root_node;	
	return 0;
}
示例#15
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);
	}
}
示例#16
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;
 }
示例#17
0
void RheiaConfigurationManager::WritePerspective( const wxString& path, const wxString& pName, const wxString& pValue, bool overwrite_existing )
{
    /* First get the node in which to write the plugin */
    wxString key(path + wxT("/perspectives"));
    xmlNode* node;
    node = RheiaXmlManager::Get()->AssertPath(key,m_root);
    xmlNode* e = RheiaXmlManager::Get()->GetUniqElement( node , key );

    xmlNode *child = e->children;

    while ( child != NULL )
    {
        wxString ChildName = RheiaC2U( (const char*) child->name );

        if ( ChildName.IsSameAs( ConfigManagerPaths::Perspective ) )
        {
            wxString pname = RheiaC2U( (const char*) xmlGetProp( child ,
                                       rxU2C(ConfigManagerPaths::LayoutAttributes::LayoutName) ) ) ;

            if ( pname.IsSameAs( pName ) )
            {
                if ( overwrite_existing )
                {
                    xmlReplaceNode( child , NULL );
                    break;
                }
                else
                    return;
            }
        }
        child = child->next;
    }

    child = xmlNewNode( NULL , rxU2C(ConfigManagerPaths::Perspective ) );
    xmlNewProp( child , rxU2C(ConfigManagerPaths::LayoutAttributes::LayoutName ) ,
                rxU2C(pName ));

    xmlAddChild( e , child );

    wxString perspective = pValue;
    key = wxT("/perspective_string");
    RheiaXmlManager::Get()->Write( key , perspective , child );
}
示例#18
0
/* :nodoc: */
static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
{
  xmlNodePtr retval ;

  retval = xmlReplaceNode(pivot, new_node) ;

  if (retval == pivot) {
    retval = new_node ; /* return semantics for reparent_node_with */
  }

  /* work around libxml2 issue: https://bugzilla.gnome.org/show_bug.cgi?id=615612 */
  if (retval->type == XML_TEXT_NODE) {
    if (retval->prev && retval->prev->type == XML_TEXT_NODE) {
      retval = xmlTextMerge(retval->prev, retval);
    }
    if (retval->next && retval->next->type == XML_TEXT_NODE) {
      retval = xmlTextMerge(retval, retval->next);
    }
  }

  return retval ;
}
示例#19
0
static GUPnPDIDLLiteFragmentResult
apply_temporary_modification (DocNode    *modified,
                              xmlNodePtr  current_node,
                              xmlNodePtr  new_node,
                              XSDData    *xsd_data)
{
        xmlNodePtr mod_cur_node = av_xml_util_find_node (modified->node,
                                                         current_node);
        xmlNodePtr new_node_copy = av_xml_util_copy_node (new_node);

        if (mod_cur_node == NULL) {
                return GUPNP_DIDL_LITE_FRAGMENT_RESULT_UNKNOWN_ERROR;
        }

        xmlUnlinkNode (new_node_copy);
        mod_cur_node = xmlReplaceNode (mod_cur_node, new_node_copy);
        xmlUnlinkNode (mod_cur_node);
        xmlFreeNode (mod_cur_node);

        if (!xsd_data_validate_doc (xsd_data, modified->doc))
                return GUPNP_DIDL_LITE_FRAGMENT_RESULT_NEW_INVALID;

        return GUPNP_DIDL_LITE_FRAGMENT_RESULT_OK;
}
示例#20
0
int main (void)
{
//	char *queryString;
	FILE *test;
	unsigned x,y;
	double contentLength;
	char* temp1;
	char* temp2;
//	int naoAchado=0;
//	char temp[1024];
	char originalString[10240];
	char processedString[10240];
	char hexa[3];
	const char *length;
	chainType *form, *aux, *first;
	char *uid;
	long long unsigned int i=1;
	xmlChar* version= "1.0";
	
//	char *paciente;
	xmlDoc *doc = NULL;
	xmlDoc *docNew = NULL;
	xmlNode *root_element = NULL;
	xmlNode *root_element_new = NULL;
	xmlNode *currently;
	xmlNode *patientFound;
//	xmlNode *info;
	//xmlNode *removed;
	xmlNode *extracted;

//	char hour[3],minute[3],second[3],day[3],month[3],year[5];

	if(!(length= getenv("CONTENT_LENGTH"))) //verifica se string lida é null
	{

		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao repassar os argumentos");
		printf("</body>\n");
		printf("</html>\n");
		exit(OK);
	}

	//converte string com o tamanho em long int
	contentLength=strtol(length, NULL, 10);
    //le linha das informacoes 1 vez com o tamanho de contentLength do stdin
    //e armazena em originalString
    fread(originalString, contentLength, 1, stdin);
    //le char por char da url substituindo os carac especiais
	for (x = 0, y = 0; x < strlen(originalString); x++, y++)
	{
		switch (originalString[x])
		{
           		/* Convert all + chars to space chars */
			case '+':
				processedString[y] = ' ';
				break;

			/* Convert all %xy hex codes into ASCII chars */
	 	   	 case '%':
				/* Copy the two bytes following the % */
				strncpy(hexa, &originalString[x + 1], 2);
				/* Skip over the hex */
				x = x + 2;
				/* Convert the hex to ASCII */				
				/* Prevent user from altering URL delimiter sequence */
				if( ((strcmp(hexa,"26")==0)) || ((strcmp(hexa,"3D")==0)) )
				{
					processedString[y]='%';
					y++;
					strcpy(processedString,hexa);
					y+=2;
					break;
				}
				processedString[y] = (char)strtol(hexa, NULL, 16);
				break;

			/* Make an exact copy of anything else */
			 default:
				processedString[y] = originalString[x];
				break;
		}
	}

	
	/* pega a stringprecessada e separa os campos **
	** &atributo=valor"\0" */

	temp1 = (char*)&processedString;
	aux = (chainType*)malloc(sizeof(chainType));
	first = (chainType*)malloc(sizeof(chainType));
	aux=first=NULL;

//	paciente=(char*)malloc(sizeof(char));
/*
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("%s",temp1);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
*/
	for (temp2=strsep(&temp1,"&"); temp2!=NULL; temp2=strsep(&temp1,"&"))
	{
        	form = (chainType*)malloc(sizeof(chainType));
       		form->attribute=strsep(&temp2,"=");
         	form->value=strsep(&temp2,"\0");
          	if (aux == NULL)
           	{
            	first = form;
            }
            else
            {
            	aux->next = form;
            }

            aux = form;
   	}
	form->next = NULL;
	if(!form)
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro: ponteiro nulo");
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}
	uid = first->value;
	aux=first->next;
/*
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("%s-%s<BR>%s-%s\n",aux->attribute,aux->value,aux->next->attribute,aux->next->value);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
*/
	doc = xmlReadFile(XML_ADDED, NULL, 256);

	if (doc == NULL) 
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao tentar abrir o arquivo.\n");
		printf("%s",XML_ADDED);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}
	root_element = xmlDocGetRootElement(doc);
	//printf("%s\n",root_element->name);

//	currently = root_element->children; comentei essa linha o codigo deve continuar funcionando!!
//	printf("%s\n",currently->name);

/*				printf("Content-type: text/html\n\n");
				printf("<html>\n");
				printf("<head>\n");
				printf("<title>Resultado</title>\n");
				printf("</head>\n");
				printf("<body>\n");*/
		
	for (currently = root_element->children; currently; currently=currently->next)
	{
		/*printf("%s\n",xmlNodeGetContent(currently->children));
		printf("%d\n",i);
		printf("%s\n",aux->value);*/
		if(i == atoi(aux->value))
		{
			patientFound = currently->children;
			
			while ((strcmp(patientFound->name, "nome")) && (patientFound))
			//{
				patientFound = patientFound->next;
				// printf("<p>%s</p>\n", patientFound->name);
			//}
			
			if (!patientFound)
			{
				printf("Content-type: text/html\n\n");
				printf("<html>\n");
				printf("<head>\n");
				printf("<title>Resultado</title>\n");
				printf("</head>\n");
				printf("<body>\n");
				printf("Erro: paciente não encontrado");
				printf("</body>\n");
				printf("</html>");
				exit(OK);
			}
			
			/*if(!strcmp(xmlNodeGetContent(patientFound),aux->next->value))       ///NAO ACEITA NOMES COM ACENTO!!!! RESOLVER DEPOIS!!!!
			{
				printf("<p>%s = %s?</p>\n",xmlNodeGetContent(patientFound),aux->next->value);*/
				extracted = xmlReplaceNode(currently,currently->next);
			//}
			
		}
		i++;
	}
	
	test = fopen(XML_REMOVED,"r");
	if(test == NULL)
	{
		docNew = xmlNewDoc(version);
		root_element_new = xmlNewNode(NULL,"doc");
		xmlDocSetRootElement(docNew, root_element_new);
//		xmlNewChild(extracted, NULL,"motivo", BAD_CAST aux->next->value);
	        xmlAddChild(root_element_new,extracted);
	}
	else
	{
		fclose(test);
		docNew = xmlReadFile(XML_REMOVED, NULL, 256);
		root_element_new = xmlDocGetRootElement(docNew);
//		xmlNewTextChild(extracted->children,NULL,"motivo",aux->next->value);
        	xmlAddChild(root_element_new,extracted);
	}

	/*  save the file that contents removed patients and free memory */

	if(xmlSaveFormatFileEnc(XML_REMOVED,docNew,"UTF-8",1) < 0 )
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao salvar arquivo<BR>\n");
		printf("%s",XML_REMOVED);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}
	xmlFreeNode(extracted);
	xmlFreeDoc(docNew);
	xmlCleanupParser();
	xmlMemoryDump();
	
	/*  save the file of patients and free memory */
	if(xmlSaveFormatFileEnc(XML_ADDED,doc,"UTF-8",1) < 0 )
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao salvar arquivo\n");
		printf("%s",XML_ADDED);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}
	xmlFreeDoc(doc);
	xmlFreeNode(currently);
	xmlCleanupParser();
	xmlMemoryDump();
	
/*		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("chegou aqui!\n");
		printf("%s",PATHFILE);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
*/		
//	test = fopen(XML_HISTORIC,"r");

	/* File Historic.xml doesn´t exist */

	/*if(test == NULL)
	{
		docNew = xmlNewDoc("1.0");
		root_element_new = xmlNewNode(NULL,"doc");
		xmlDocSetRootElement(docNew, root_element_new);
		extracted=xmlNewNode(NULL,"paciente");
		xmlNewChild(extracted,NULL,"nome",aux->next->value);
		info=xmlNewNode(NULL,"info");
	}

	// File Historic.xml exist and need to find his position if there is a historic of the patient

	else
	{
		fclose(test);
		docNew = xmlReadFile(XML_HISTORIC, NULL, 256);
		root_element_new = xmlDocGetRootElement(docNew);
		for (currently = root_element_new->children; ((naoAchado == 0) && (strcmp(xmlNodeGetContent(currently->children),aux->value) ) ); )
		{
	             if(currently->next == NULL)
        	        naoAchado++;
               	     else
	                currently=currently->next;
//printf("%s\n",xmlNodeGetContent(currently->children));
		}
//		xmlNewTextChild(extracted->children,NULL,"motivo",aux->next->value);

		// if currently is null, there is no historic of that patient 

		if(naoAchado)
		{
			extracted=xmlNewNode(NULL,"paciente");
			xmlNewChild(extracted,NULL,"numeroPaciente",aux->value);  // faltar verificar se aux->value contem msm o numero do paciente
			info=xmlNewNode(NULL,"info");			
		}

		// there is already a historic of the patient

		else
		{
			extracted=currently;
			info=extracted->children->next;			
		}
	}
	removed=xmlNewNode(NULL,"removido");

	// get time: hour,minute,second, day,month,year

	if(getFullDataParts(hour,minute,second,day,month,year))
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao pegar data<BR>\n");
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}
	xmlNewChild(removed,NULL,"day",day);
							printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("chegou aqui![4]\n");
		printf("%s",PATHFILE);
		printf("</body>\n");
		printf("</html>");
		exit(OK);*/
	/*xmlNewChild(removed,NULL,"month",month);
	xmlNewChild(removed,NULL,"year",year);
	xmlNewChild(removed,NULL,"hour",hour);
	xmlNewChild(removed,NULL,"minute",minute);
	xmlNewChild(removed,NULL,"second",second);
	xmlNewChild(removed,NULL,"user",MEDIC);
	xmlNewChild(removed,NULL,"reason",aux->next->value);
	xmlAddChild(info,removed);
	xmlAddChild(extracted,info);
	xmlAddChild(root_element_new,extracted);

	if(xmlSaveFormatFileEnc(XML_HISTORIC,docNew,"UTF-8",1) < 0 )
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao salvar arquivo<BR>\n");
		printf("%s",XML_HISTORIC);
		printf("</body>\n");
		printf("</html>");
		exit(OK);
	}

	xmlFreeNode(extracted);
	xmlFreeNode(currently);
	xmlFreeNode(info);
	xmlFreeNode(removed);
	xmlFreeDoc(docNew);
	xmlCleanupParser();
	xmlMemoryDump();
  
	root_element = xmlDocGetRootElement(doc);
	printf("%s\n",root_element->name);

	for (currently = root_element->children; currently; currently=currently->next)
	{
		printf("%s\n",currently->name);
	}
*/	
	printf("Content-type: text/html\n\n");
	printf("<html>\n");
	printf("<head>\n");
	printf("<title>.:. Neural TB .:. Paciente removido com sucesso</title>\n");
	printf("<script language=\"javascript\" src=\"../js/motivo.js\" charset=\"UTF-8\"></script>\n");
	printf("<script language=\"javascript\" src=\"../js/xml.js\" charset=\"UTF-8\"></script>\n");
	printf("</head>\n");
	printf("<table height=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n");
    printf("<tr bgcolor=\"#CCCCCC\">\n");
	printf("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");
	printf("<td><b><u><font size=\"5\">Menu</font></u></b></td>\n");
	printf("<td>&nbsp;</td>\n");
    printf("</tr>\n");
    printf("<tr bgcolor=\"#CCCCCC\">");
    printf("<td>&nbsp;</td>");
    printf("<td width=\"100%c\">",37);
	printf("<a href=\"formulario.cgi?uid=%s\">Adicionar Paciente</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n", uid);
	printf("<a href=\"busca.cgi?uid=%s\">Buscar/Editar/Remover</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", uid);
	printf("<a href=\"backup.cgi\"> Back-up</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
	printf("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    printf("<a href=\"principal.cgi?uid=%s\">P&aacute;gina principal</a>\n", uid);
	printf("</td>\n");
    printf("<td></td>\n");
    printf("</tr>\n");
    printf("<tr bgcolor=\"#CCCCCC\">");
    printf("<td>&nbsp;</td>\n");
    printf("<td>\n");
    printf("<a href=\"exibirPacientes.cgi?uid=%s\">Exibir question&aacute;rios</a> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n", uid);
    printf("<a href=\"exibirRecusa.cgi?uid=%s\">Exibir recusas</a>\n", uid);
    printf("</td>\n");
    printf("<td></td>\n");
    printf("</tr>\n");
    printf(" </table>\n");
	printf("<h3><div align='center'>Paciente removido com sucesso!</div></h3>\n");
	printf("</body>\n");
	printf("</html>");

	for (aux=form=first; aux!=NULL; form=aux)
	{
		aux = form->next;
		free (form);
	}
		
	exit(OK);
}
示例#21
0
文件: node.c 项目: RareHare/reactos
HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
        IXMLDOMNode **ret)
{
    xmlnode *old_child, *new_child;
    xmlDocPtr leaving_doc;
    xmlNode *my_ancestor;
    int refcount = 0;

    /* Do not believe any documentation telling that newChild == NULL
       means removal. It does certainly *not* apply to msxml3! */
    if(!newChild || !oldChild)
        return E_INVALIDARG;

    if(ret)
        *ret = NULL;

    old_child = get_node_obj(oldChild);
    if(!old_child) return E_FAIL;

    if(old_child->node->parent != This->node)
    {
        WARN("childNode %p is not a child of %p\n", oldChild, This);
        return E_INVALIDARG;
    }

    new_child = get_node_obj(newChild);
    if(!new_child) return E_FAIL;

    my_ancestor = This->node;
    while(my_ancestor)
    {
        if(my_ancestor == new_child->node)
        {
            WARN("tried to create loop\n");
            return E_FAIL;
        }
        my_ancestor = my_ancestor->parent;
    }

    if(!new_child->node->parent)
        if(xmldoc_remove_orphan(new_child->node->doc, new_child->node) != S_OK)
            WARN("%p is not an orphan of %p\n", new_child->node, new_child->node->doc);

    leaving_doc = new_child->node->doc;

    if (leaving_doc != old_child->node->doc)
        refcount = xmlnode_get_inst_cnt(new_child);

    if (refcount) xmldoc_add_refs(old_child->node->doc, refcount);
    xmlReplaceNode(old_child->node, new_child->node);
    if (refcount) xmldoc_release_refs(leaving_doc, refcount);
    new_child->parent = old_child->parent;
    old_child->parent = NULL;

    xmldoc_add_orphan(old_child->node->doc, old_child->node);

    if(ret)
    {
        IXMLDOMNode_AddRef(oldChild);
        *ret = oldChild;
    }

    return S_OK;
}
示例#22
0
int main (void)
{
	char *formName, *pid, *username, *newPid;
	boolean found_patient;
	FILE *document;
	
	/* libcgi declarations */
	formvars *first_input, *input;
	
	/* libxml2 declarations */
	xmlChar *strUTF = NULL;
	xmlDocPtr doc;
	xmlNodePtr root_element, cur_node, new_form, new_node, edited_patient, old_patient;
	
	/*
	 * this initialize the library and check potential ABI mismatches
	 * between the version it was compiled for and the actual shared
	 * library used.
	 */
	LIBXML_TEST_VERSION
	
/******************************************************************************
 *            READ CONTENT STRING FROM SERVER.		*
 *            PROCESS DATA.						*
 *            CREATE A LINKED LIST.					*
 ******************************************************************************/
	
	cgi_init();
	first_input = cgi_process_form();
	newPid = cgi_param("numeroGeral");
	pid = cgi_param("antigoNumeroGeral");
	formName = cgi_param("form");
	//username = cgi_param("uid");
	
	if(!(username= getenv("REMOTE_USER"))) //verifica se string lida é null
	{
		printf("Content-type: text/html\n\n");
		printf("<html>\n");
		printf("<head>\n");
		printf("<title>Resultado</title>\n");
		printf("</head>\n");
		printf("<body>\n");
		printf("Erro ao verificar o usuário.");
		printf("</body>\n");
		printf("</html>\n");
		exit(0);
	}
	
	if ((!pid) || (!formName))
	{
		printError("ID do paciente e nome do formul&aacute;rio n&atilde;o foram enviados");
		usualFreeMemory(NULL);
		exit(0);
	}

/******************************************************************************
 *            OPENING AND PARSING AN XML FILE TO A TREE                       *
 ******************************************************************************/	
 
	document = fopen(XML_FILE_PATH, "r+");
 	
 	if (document == NULL) {
        printError("O arquivo de pacientes n&atilde;o pode ser aberto");
        exit(0);
    }
    
	if(flock(fileno(document), LOCK_EX)) {
        printError("Erro ao trancar o arquivo");
       	fclose(document);
        exit(0);
    }
    
   //printWait("Trancado!");
   //sleep(20);
    
	doc = xmlReadFd(fileno(document), XML_FILE_PATH, NULL, XML_PARSE_NOBLANKS);
	if (doc == NULL)
	{
		printError("Failed to parse doc");
		usualFreeMemory(NULL);
		flock(fileno(document), LOCK_EX);
		fclose(document);
		exit(0);
	}
	
	root_element = xmlDocGetRootElement(doc);
	
/******************************************************************************
 *            SEARCH THE SAME <numeroGeral>                                   *
 ******************************************************************************/
		
	cur_node = root_element->children;	/* Get the node <paciente> if file isn't empty */
	if (!cur_node) //test!!!! printf!! pode-se tb na remocao exigir a remocao do arquivo se o paciente excluido for o unico do arquivo
		found_patient = false;
	
	else
	{
		/* looping through patients looking for the right patient */
		
		for (found_patient = false; ((!found_patient) && (cur_node)); cur_node = cur_node->next)
		{
			cur_node = cur_node->children; /* <triagem> */
			cur_node = cur_node->children; /* <numeroGeral> ? */
			
			while ((!xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) && (cur_node))
				cur_node = cur_node->next;
			
			if (xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral"))
			{
				if (xmlStrEqual(cur_node->children->content, BAD_CAST pid))
				{
					found_patient = true;
					old_patient = cur_node->parent; /*old_paciente recebe o noh <triagem> do paciente que possui o numeroGeral procurado */
				}
				else
				{
					cur_node = cur_node->parent; /* <triagem> */
					cur_node = cur_node->parent; /* <paciente> */
				}
			}
			else
			{
				printError("Erro de forma&ccedil;&atilde;o do XML. Tem paciente sem n&uacute;mero geral.");
				usualFreeMemory(doc);
				flock(fileno(document), LOCK_EX);
				fclose(document);
				exit(0);
			}
		}
	}

/******************************************************************************
 *            CHECK IF PATIENT WAS FOUND		*
 *            IF TRUE, EXIT 					*
 ******************************************************************************/
	
	if (!found_patient)
	{
		printError("Este paciente n&atilde;o existe.");
		usualFreeMemory(doc);
		flock(fileno(document), LOCK_EX);
		fclose(document);
		exit(0);
	}

/******************************************************************************
			* Verificando se o novo numero geral jah existe *
*******************************************************************************/
		
	cur_node = root_element->children;	/* Get the node <paciente> if file isn't empty */
	if (!cur_node) //test!!!! printf!! pode-se tb na remocao exigir a remocao do arquivo se o paciente excluido for o unico do arquivo
		found_patient = false;
	
	else
	{
		/* looping through patients looking for the right patient */
		
		for (found_patient = false; ((!found_patient) && (cur_node)); cur_node = cur_node->next)
		{
			cur_node = cur_node->children; /* <triagem> */
			cur_node = cur_node->children; /* <numeroGeral> ? */
			
			while ((!xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral")) && (cur_node))
				cur_node = cur_node->next;
			
			if (xmlStrEqual(cur_node->name, BAD_CAST "numeroGeral"))
			{
				if (xmlStrEqual(cur_node->children->content, BAD_CAST newPid))
				{
					found_patient = true;
					old_patient = cur_node->parent; /*old_paciente recebe o noh <triagem> do paciente que possui o numeroGeral procurado */
				}
				else
				{
					cur_node = cur_node->parent; /* <triagem> */
					cur_node = cur_node->parent; /* <paciente> */
				}
			}
			else
			{
				printError("Erro de forma&ccedil;&atilde;o do XML. Tem paciente sem n&uacute;mero geral.");
				usualFreeMemory(doc);
				flock(fileno(document), LOCK_EX);
				fclose(document);
				exit(0);
			}
		}
	}
	
/******************************************************************************
			* Comfirmando se novo numero geral jah existe *
*******************************************************************************/

	if((found_patient) && (strcmp(newPid,pid) != 0))
	{
		printError("O novo n&uacute;mero geral escolhido j&aacute; existe.");
		usualFreeMemory(doc);
		flock(fileno(document), LOCK_EX);
		fclose(document);
		exit(0);
	}

/******************************************************************************
 *            CRIANDO NOVO FORMULARIO DE TRIAGEM                                        *
 ******************************************************************************/
	
	edited_patient = xmlNewNode (NULL,BAD_CAST "triagem");
	
/******************************************************************************
 *            ADD NEW FORM                                                    *
 ******************************************************************************/
	
	strUTF = fixCgiStr(BAD_CAST formName);
	if (!strUTF)
	{
		cgi_init_headers();
		printError("Erro na convers&atilde;o de formName para UTF-8");
		usualFreeMemory(doc);
		flock(fileno(document), LOCK_EX);
		fclose(document);
		exit(0);
	}
	
	new_form = xmlNewChild (edited_patient, NULL, BAD_CAST strUTF, NULL);
	free(strUTF);//frees formName
	
	for (input = first_input; input; input = input->next)
	{
		if (!strcmp(input->name,"form"))
			input = input->next;
		
		if (!strcmp(input->name,"uid"))
			input = input->next;
		
		if (!strcmp(input->name,"antigoNumeroGeral"))
			input = input->next;
		
		/* Validate tag name input against UTF-8 */
		strUTF = fixCgiStr((unsigned char *)input->name);
		if (!strUTF)
		{
			printError("Erro na convers&atilde;o de input->name para UTF-8");
			usualFreeMemory(doc);
			flock(fileno(document), LOCK_EX);
			fclose(document);
			exit(0);
		}
		
		new_node = xmlNewNode (NULL, strUTF);
		free(strUTF);//frees input->name
		
		/* Validate tag value input against UTF-8 */
		strUTF = fixCgiStr((unsigned char *)input->value);
		if (!strUTF)
		{
			printError("Erro na convers&atilde;o de input->value para UTF-8");
			usualFreeMemory(doc);
			flock(fileno(document), LOCK_EX);
			fclose(document);
			exit(0);
		}
		
		xmlNodeAddContent (new_node, strUTF);
		free(strUTF);//frees input->value
		
		xmlAddChild (new_form, new_node);
	}

/******************************************************************************
*	Substituindo o noh antigo pelo novo		*
******************************************************************************/

	xmlReplaceNode (old_patient, edited_patient->children);
	xmlFreeNode (old_patient);
	
/******************************************************************************
 *            DUMPING DOCUMENT TO FILE		*
 ******************************************************************************/
	
	if ((xmlSaveFormatFileEnc(XML_FILE_PATH, doc, "ISO-8859-1", 1)) < 0)
	{
		printError("Erro ao salvar arquivo");
		usualFreeMemory(doc);
		xmlFreeNode(edited_patient);
		flock(fileno(document), LOCK_EX);
		fclose(document);
		exit(0);
	}
	
	/*remove(XML_FILE_PATH);
    
    if (rename(XML_TEMP_FILE, XML_FILE_PATH))
    {
        printError("Erro ao renomear o arquivo atualizado");
        usualFreeMemory(doc);
        exit(0);
    }*/

/******************************************************************************
 *            FREE MEMORY AND EXIT			*
 ******************************************************************************/

	printSuccess(username);
	usualFreeMemory(doc);
	xmlFreeNode(edited_patient);
	flock(fileno(document), LOCK_EX);
	fclose(document);
	autoBackup();
	return 0;
}
示例#23
0
ReturnCode openExternalFiles(TixiDocument* aTixiDocument, int* number)
{
  int iNode = 0;
  int handle = aTixiDocument->handle;
  xmlNodePtr cur = NULL;
  ReturnCode error = SUCCESS;

  assert(aTixiDocument != NULL);
  *number = 0;

  while(1) {
    // loop until there are no externaldata nodes included

    xmlXPathObjectPtr xpathObject = XPathEvaluateExpression(aTixiDocument->docPtr, "//externaldata");
    xmlNodeSetPtr nodeset = NULL;
    char* externalDataNodeXPath, *externalDataDirectoryXPath, *externalDataDirectory, *resolvedDirectory;
    int externalFileCount = 0;

    if (!xpathObject) {
      // no more external data, stop
      break;
    }

    nodeset = xpathObject->nodesetval;
    if (!nodeset || nodeset->nodeNr < 1) {
      break;
    }

    // goto the first node that is an element
    for (iNode = 0; iNode < nodeset->nodeNr; ++iNode) {
      cur = nodeset->nodeTab[iNode];
      if (cur->type == XML_ELEMENT_NODE) {
        break; // for loop
      }
    }
    if (iNode == nodeset->nodeNr) {
      // no element node found
      xmlXPathFreeObject(xpathObject);
      break; // while loop
    }

    // found external data node
    xmlXPathFreeObject(xpathObject);

    /* get nodes XPath */
    externalDataNodeXPath = (char*) xmlGetNodePath(cur);


    /* now get the subdirectory */
    externalDataDirectoryXPath = buildString("%s/%s", externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_PATH);

    error = tixiGetTextElement(handle, externalDataDirectoryXPath, &externalDataDirectory);
    free(externalDataDirectoryXPath);
    if (error) {
      printMsg(MESSAGETYPE_ERROR, "Error: openExternalFiles returns %d. No path defined in externaldata node!\n", error);
      xmlFree(externalDataNodeXPath);
      return OPEN_FAILED;
    }

    // resolv data directory (in case of relative paths)
    resolvedDirectory = resolveDirectory(aTixiDocument->dirname, externalDataDirectory);

    /* now get number and names of all external files */
    tixiGetNamedChildrenCount(handle, externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_FILENAME, &externalFileCount);
    if (externalFileCount == 0) {
      printMsg(MESSAGETYPE_ERROR, "Error: no filename nodes defined in externalData node.\n");
      xmlFree(externalDataNodeXPath);
      free(resolvedDirectory);
      return OPEN_FAILED;
    }

    for (iNode = 1; iNode <= externalFileCount; iNode++) {
      char* externalFileName, *externalFullFileName, *newDocumentString, *fileNameXPath;
      xmlDocPtr xmlDocument = NULL;

      fileNameXPath = buildString("%s/filename[%d]", externalDataNodeXPath, iNode);

      tixiGetTextElement(handle, fileNameXPath, &externalFileName);
      free(fileNameXPath);

      /* Build complete filename */
      externalFullFileName = buildString("%s%s", resolvedDirectory, externalFileName);

      /* open files */
      newDocumentString = loadExternalFileToString(externalFullFileName);
      if (newDocumentString == NULL) {
        printMsg(MESSAGETYPE_ERROR, "\nError in fetching external file \"%s\".\n", externalFullFileName);
        free(externalFullFileName);
        xmlFree(externalDataNodeXPath);
        free(resolvedDirectory);
        return OPEN_FAILED;
      }

      /* now parse the file to DOM */
      xmlDocument = xmlReadMemory(newDocumentString, (int) strlen(newDocumentString), "urlResource", NULL, 0);
      free(newDocumentString);

      if (xmlDocument) {
        xmlNodePtr rootToInsert = xmlDocGetRootElement(xmlDocument);

        xmlNodePtr parent = cur->parent;
        if (parent) {
          xmlChar* nodePathNew = NULL;
          char* dataURI = localPathToURI(externalDataDirectory);
          xmlNodePtr nodeToInsert = xmlDocCopyNode(rootToInsert, aTixiDocument->docPtr, 1);

          /* add metadata to node, to allow saving external node data */
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME, (xmlChar*) externalFileName);

          /* save the sub-directory */
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY, (xmlChar*) dataURI);
          free(dataURI);

          /* save the external data node position */
          nodePathNew = xmlGetNodePath(parent);
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH, nodePathNew);
          xmlFree(nodePathNew);

          /* replace externalData node with xml file's content */
          xmlReplaceNode(cur, nodeToInsert);

          /* file could be loaded and parsed, increase the counter */
          (*number)++;
        }

        xmlFreeDoc(xmlDocument);
      }
      else {
        printMsg(MESSAGETYPE_WARNING,
                 "Document %s will be ignored. No valid XML document!\n",
                 externalFullFileName);

        /* remove external data node */
        xmlUnlinkNode(cur);
      }
      free(externalFullFileName);
    } /* end for files */

    free(resolvedDirectory);
    free(externalDataNodeXPath);
    xmlFreeNode(cur);
  }


  if (*number == 0) {
    printMsg(MESSAGETYPE_WARNING, "WARNING: Unable to load any externaldata files.\n");
  }

  return SUCCESS;
}
示例#24
0
int main (void)
{
	char *formName, *pid, *username, *paciente;
	boolean found_patient;
	int atual, paciente_id;
	
	/* libcgi declarations */
	formvars *first_input, *input;
	
	/* libxml2 declarations */
	xmlChar *strUTF = NULL;
	xmlDocPtr doc;
	xmlNodePtr root_element, cur_node, new_form, new_node, edited_patient, old_patient;
	
	/*
	 * this initialize the library and check potential ABI mismatches
	 * between the version it was compiled for and the actual shared
	 * library used.
	 */
	LIBXML_TEST_VERSION
	
/******************************************************************************
 *            READ CONTENT STRING FROM SERVER.		*
 *            PROCESS DATA.						*
 *            CREATE A LINKED LIST.					*
 ******************************************************************************/
	
	cgi_init();
	first_input = cgi_process_form();
	pid = cgi_param("pid");
	username = cgi_param("uid");
	paciente = cgi_param("paciente");
	
	paciente_id = atoi(paciente);
	

/******************************************************************************
 *            OPENING AND PARSING AN XML FILE TO A TREE                       *
 ******************************************************************************/	
 
	doc = xmlReadFile(XML_FILE_PATH, NULL, XML_PARSE_NOBLANKS);
	if (doc == NULL)
	{
		printError("Failed to parse doc");
		usualFreeMemory(NULL);
		exit(0);
	}
	root_element = xmlDocGetRootElement(doc);
	cur_node = root_element->children;
	
	
	
/******************************************************************************
 *            SEARCH THE SAME <numeroGeral>                                   *
 ******************************************************************************/
		
	//atual = 1;
	atual = cur_node->getElementsByTagName("id");
	
		while((cur_node != NULL) && (atual->value != paciente_id ))
		{
				cur_node = cur_node->next;
				//atual ++;
				atual = cur_node->getElementsByTagName("id");
		}
		
		old_patient = cur_node;

		
/******************************************************************************
 *            CHECK IF PATIENT WAS FOUND		*
 *            IF TRUE, EXIT 					*
 ******************************************************************************/
	
	
/******************************************************************************
 *            CRIANDO NOVO FORMULARIO DE TRIAGEM                                        *
 ******************************************************************************/
	
	edited_patient = xmlNewNode (NULL,BAD_CAST "paciente");
	
/******************************************************************************
 *            ADD NEW FORM                                                    *
 ******************************************************************************/
	
	new_form = edited_patient;

	for (input = first_input; input; input = input->next)
	{
		if (!strcmp(input->name,"form"))
			input = input->next;
			
		if (!strcmp(input->name,"uid"))
			input = input->next;
			
		if (!strcmp(input->name,"paciente"))
			input = input->next;
		
		
		/* Validate tag name input against UTF-8 */
		strUTF = input->name;
		//printf("%s : \n", strUTF);
		new_node = xmlNewNode (NULL, strUTF);
		free(strUTF);//frees input->name
		
		
		/* Validate tag value input against UTF-8 */
		strUTF = input->value;
		//printf("%s <br>\n", strUTF);
		xmlNodeAddContent (new_node, strUTF);
		free(strUTF);//frees input->value
		
		
		xmlAddChild (new_form, new_node);
	}

	/*printf ("</span>");
		printf ("\t</body>\n");
	printf ("</html>");
	
	return 0;*/
	
	//printf ("</html>\n");
	//printf ("\t</body>\n");
	//usualFreeMemory(NULL);
	//exit(0);
/******************************************************************************
*	Substituindo o noh antigo pelo novo		*
******************************************************************************/

	xmlReplaceNode (old_patient, edited_patient);
	xmlFreeNode (old_patient);
	
/******************************************************************************
 *            DUMPING DOCUMENT TO FILE		*
 ******************************************************************************/
	
	if ((xmlSaveFormatFileEnc(XML_TEMP_FILE, doc, "UTF-8", 1)) < 0)
	{
		remove(XML_TEMP_FILE);
		printError("Erro ao salvar arquivo");
		usualFreeMemory(doc);
		exit(0);
	}
	
	remove(XML_FILE_PATH);
    
    if (rename(XML_TEMP_FILE, XML_FILE_PATH))
    {
        printError("Erro ao renomear o arquivo atualizado");
        usualFreeMemory(doc);
        exit(0);
    }

/******************************************************************************
 *            FREE MEMORY AND EXIT			*
 ******************************************************************************/

	printSuccess(username);
	
	usualFreeMemory(doc);
	
	xmlFreeNode(edited_patient);
	
	return 0;
}