#include #include #include /* Compile with: gcc -o ns ns.c `pkg-config --libs --cflags libxml-2.0` */ static xmlDoc* my_parse_document (const xmlChar *content) { xmlParserCtxt *parserCtxt = NULL; xmlDoc *document = NULL; parserCtxt = xmlCreateMemoryParserCtxt(content, xmlStrlen(content)); if (xmlParseDocument(parserCtxt) == 0) { document = parserCtxt->myDoc; parserCtxt->myDoc = NULL; } xmlFreeParserCtxt(parserCtxt); return document; } int main (int argc, char **argv) { const xmlChar *ns_uri = "http://dummies.org"; xmlDoc *document = NULL; xmlChar *value = NULL; xmlNode *root = NULL; xmlNode *node = NULL; document = my_parse_document( "" ); if (document == NULL) { printf("Failed to parse XML\n"); return 1; } root = document->children; printf("Root.name = %s\n", root->name); value = xmlGetProp(root, "name"); printf("xmlGetProp(root) is %s\n", value); if (value) xmlFree(value); value = xmlGetNsProp(root, "name", ns_uri); printf("xmlGetNsProp(root) is %s\n", value); if (value) xmlFree(value); value = xmlGetNoNsProp(root, "name"); printf("xmlGetNoNsProp(root) is %s\n", value); if (value) xmlFree(value); printf("\n"); node = root->children; printf("Node.name = %s\n", node->name); value = xmlGetProp(node, "name"); printf("xmlGetProp(Value:scalar) = %s\n", value); if (value) xmlFree(value); value = xmlGetNsProp(node, "name", ns_uri); printf("xmlGetNsProp(Value:scalar) = %s\n", value); if (value) xmlFree(value); value = xmlGetNoNsProp(node, "name"); printf("xmlGetNoNsProp(Value:scalar) = %s\n", value); if (value) xmlFree(value); xmlFreeDoc(document); xmlCleanupParser(); return 0; }