Sha256: 03b566f10d2b0f69663a107b15ac0217e6dbc0fda7ce0cb638ccc189e1dd65bd

Contents?: true

Size: 1.46 KB

Versions: 153

Compression:

Stored size: 1.46 KB

Contents

<![CDATA[
#include <libxml/parser.h>
#include <libxml/xpath.h>

xmlDocPtr
getdoc (char *docname) {
	xmlDocPtr doc;
	doc = xmlParseFile(docname);
	
	if (doc == NULL ) {
		fprintf(stderr,"Document not parsed successfully. \n");
		return NULL;
	}

	return doc;
}

xmlXPathObjectPtr
getnodeset (xmlDocPtr doc, xmlChar *xpath){
	
	xmlXPathContextPtr context;
	xmlXPathObjectPtr result;

	context = xmlXPathNewContext(doc);
	if (context == NULL) {
		printf("Error in xmlXPathNewContext\n");
		return NULL;
	}
	result = xmlXPathEvalExpression(xpath, context);
	xmlXPathFreeContext(context);
	if (result == NULL) {
		printf("Error in xmlXPathEvalExpression\n");
		return NULL;
	}
	if(xmlXPathNodeSetIsEmpty(result->nodesetval)){
		xmlXPathFreeObject(result);
                printf("No result\n");
		return NULL;
	}
	return result;
}
int
main(int argc, char **argv) {

	char *docname;
	xmlDocPtr doc;
	xmlChar *xpath = (xmlChar*) "//keyword";
	xmlNodeSetPtr nodeset;
	xmlXPathObjectPtr result;
	int i;
	xmlChar *keyword;
		
	if (argc <= 1) {
		printf("Usage: %s docname\n", argv[0]);
		return(0);
	}

	docname = argv[1];
	doc = getdoc(docname);
	result = getnodeset (doc, xpath);
	if (result) {
		nodeset = result->nodesetval;
		for (i=0; i < nodeset->nodeNr; i++) {
			keyword = xmlNodeListGetString(doc, nodeset->nodeTab[i]->xmlChildrenNode, 1);
		printf("keyword: %s\n", keyword);
		xmlFree(keyword);
		}
		xmlXPathFreeObject (result);
	}
	xmlFreeDoc(doc);
	xmlCleanupParser();
	return (1);
}
]]>

Version data entries

153 entries across 135 versions & 5 rubygems

Version Path
cairo-1.16.1-x86-mingw32 vendor/local/share/doc/libxml2-2.9.8/html/tutorial/includexpath.c
cairo-1.16.1-x64-mingw32 vendor/local/share/doc/libxml2-2.9.8/html/tutorial/includexpath.c
cairo-1.16.0-x86-mingw32 vendor/local/share/doc/libxml2-2.9.8/html/tutorial/includexpath.c
cairo-1.16.0-x64-mingw32 vendor/local/share/doc/libxml2-2.9.8/html/tutorial/includexpath.c
cairo-1.15.14-x86-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.14-x64-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.13-x64-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.13-x86-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.12-x64-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.12-x86-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.11-x64-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.11-x86-mingw32 vendor/local/share/doc/libxml2-2.9.7/html/tutorial/includexpath.c
cairo-1.15.10-x86-mingw32 vendor/local/share/doc/libxml2-2.9.6/html/tutorial/includexpath.c
cairo-1.15.10-x64-mingw32 vendor/local/share/doc/libxml2-2.9.6/html/tutorial/includexpath.c
cairo-1.15.9-x64-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c
cairo-1.15.9-x86-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c
cairo-1.15.8-x86-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c
cairo-1.15.8-x64-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c
cairo-1.15.7-x64-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c
cairo-1.15.7-x86-mingw32 vendor/local/share/doc/libxml2-2.9.4/html/tutorial/includexpath.c