Created
February 19, 2018 20:36
-
-
Save anonymous/2a0995ffd42a2ec132d6c69dacb63e75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<foo> | |
<bar example="hello"/> | |
</foo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <libxml/xpath.h> | |
int main(int argc, char **argv) | |
{ | |
xmlDocPtr doc; | |
xmlXPathContextPtr ctx; | |
xmlXPathObjectPtr obj; | |
doc = xmlReadFile("document.xml", NULL, 0); | |
ctx = xmlXPathNewContext(doc); | |
obj = xmlXPathEvalExpression(BAD_CAST "/foo/bar/@example", ctx); | |
if (!xmlXPathNodeSetIsEmpty(obj->nodesetval)) { | |
xmlChar *value = xmlNodeGetContent(obj->nodesetval->nodeTab[0]); | |
puts((char *) value); | |
xmlFree(value); | |
} | |
xmlXPathFreeObject(obj); | |
xmlXPathFreeContext(ctx); | |
xmlFreeDoc(doc); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment