Example #1
0
char *ReadElement(const char *Path,const char *NodeElement)
{
	char *Val = NULL;
	IXML_Document *doc = NULL;
	IXML_NodeList *node = NULL;
	IXML_Node *NodePtr = NULL;

	if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER)
		goto EXIT_THIS;

	node = ixmlDocument_getElementsByTagName(doc, NodeElement);

	if (node) 
	{
		if (NodePtr = ixmlNodeList_item(node, 0)) 
		{
			NodePtr = ixmlNode_getFirstChild(NodePtr);
			if(!NodePtr)
			{
				Val = (NULL);
			}
			Val = NodePtr->nodeValue;//strdup(NodePtr->nodeValue);
			if(!Val)
			{
				Val = (NULL);
			}
		} 
	}

	if (node)
		ixmlNodeList_free(node);
	ixmlDocument_free(doc);  
EXIT_THIS:
	return Val;
}
Example #2
0
int
main (int argc, char* argv[])
{
	int i;

	if (argc < 2) {
		fprintf (stderr, "Usage: %s [xml files to load]\n",
			 argv[0]);
		exit (EXIT_FAILURE);
	}

	for (i = 1; i < argc; i++) {
		int rc;
		IXML_Document* doc = NULL;
		DOMString s;
		char* p;

		printf ("Test \"%s\" \n", argv[i]);
		printf ("    Loading ... ");
		fflush (stdout);

		rc = ixmlLoadDocumentEx (argv[i], &doc);
		if (rc != IXML_SUCCESS) {
			fprintf (stderr, 
				 "** error : can't load document %s : "
				 "error %d (%s)\n",
				 argv[i], rc, get_ixml_error_string (rc));
			exit (EXIT_FAILURE);
		}

		printf ("OK\n");

		printf ("    Printing ... ");
		fflush (stdout);
		
		s = ixmlPrintDocument (doc);
		if (s == NULL || s[0] == '\0') {
			fprintf (stderr, 
				 "** error : can't print loaded document %s\n",
				 argv[i]);
			exit (EXIT_FAILURE);
		}
		p = s + strlen(s)-1;
		while (isspace(*p) && p > s)
			p--;
		if (*s != '<' || *p != '>') {
			fprintf (stderr, 
				 "** error : malformed printed document '%s' :"
				 "%s\n", argv[i], s);
			exit (EXIT_FAILURE);
		}

		printf ("OK\n");

		ixmlFreeDOMString (s);
		ixmlDocument_free (doc);
	}
	
	exit (EXIT_SUCCESS);
}
Example #3
0
IXML_Document *ixmlLoadDocument(const char *xmlFile)
{
	IXML_Document *doc = NULL;

	ixmlLoadDocumentEx(xmlFile, &doc);

	return doc;
}
Example #4
0
//path,  friendlyName
static void UpdateValue(const char *Path,const char *NodeElement, char *NewValue)
{
	char *Buf = NULL;

	IXML_Document *doc = NULL;
	IXML_NodeList *node = NULL;
	IXML_Node *NodePtr = NULL;

	if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER)
		goto EXIT_THIS;

	node = ixmlDocument_getElementsByTagName(doc, NodeElement);

	if (node) 
	{
		if (NodePtr = ixmlNodeList_item(node, 0)) 
		{
			NodePtr = ixmlNode_getFirstChild(NodePtr);
			ixmlNode_setNodeValue(NodePtr,NewValue);
		} 
	}
	else
	{
		goto EXIT_XML;
	}

	Buf = ixmlPrintDocument(doc);

	if(WriteFile(Path,Buf) != SUCCESS)
		goto EXIT_THIS;

EXIT_XML:
	if (node)
		ixmlNodeList_free(node);
	free(Buf);
	ixmlDocument_free(doc);  
EXIT_THIS:
	return;
}
struct xmldoc * xmldoc_fromdoc(const char *uri)
{
	IXML_Document *doc;
	ixmlLoadDocumentEx(uri, &doc);
	return (struct xmldoc*) doc;
}