// // Author: Wolfgang Spraul // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version // 3 of the License, or (at your option) any later version. // #include #include #include #include #include #include #include #include static const xmlChar* empty_svg = (const xmlChar*) "\n" "\n" " \n" " \n" " \n" "\n"; int main(int argc, char** argv) { xmlDocPtr doc = 0; xmlXPathContextPtr xpathCtx = 0; xmlXPathObjectPtr xpathObj = 0; xmlInitParser(); doc = xmlParseDoc(empty_svg); if (!doc) { fprintf(stderr, "Internal error %i.\n", __LINE__); goto fail_xml; } xpathCtx = xmlXPathNewContext(doc); if (!xpathCtx) { fprintf(stderr, "Cannot create XPath context.\n"); goto fail_xml; } xmlXPathRegisterNs(xpathCtx, BAD_CAST "svg", BAD_CAST "http://www.w3.org/2000/svg"); xpathObj = xmlXPathEvalExpression(BAD_CAST "//svg:*[@id='root']", xpathCtx); if (!xpathObj) { fprintf(stderr, "Cannot evaluate root expression.\n"); goto fail_xml; } if (!xpathObj->nodesetval) { fprintf(stderr, "Cannot find root node.\n"); goto fail_xml; } if (xpathObj->nodesetval->nodeNr != 1) { fprintf(stderr, "Found %i root nodes.\n", xpathObj->nodesetval->nodeNr); goto fail_xml; } { xmlNodePtr new_node; int i; for (i = 0; i < 10; i++) { new_node = xmlNewChild(xpathObj->nodesetval->nodeTab[0], 0 /* xmlNsPtr */, BAD_CAST "use", 0 /* content */); xmlSetProp(new_node, BAD_CAST "xlink:href", BAD_CAST "lib.svg#IOB"); xmlSetProp(new_node, BAD_CAST "x", xmlXPathCastNumberToString(50+i*50)); xmlSetProp(new_node, BAD_CAST "y", BAD_CAST "50"); xmlSetProp(new_node, BAD_CAST "width", BAD_CAST "50"); xmlSetProp(new_node, BAD_CAST "height", BAD_CAST "50"); } } xmlDocDump(stdout, doc); xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); xmlCleanupParser(); return EXIT_SUCCESS; fail_xml: if (xpathObj) xmlXPathFreeObject(xpathObj); if (xpathCtx) xmlXPathFreeContext(xpathCtx); if (doc) xmlFreeDoc(doc); xmlCleanupParser(); return EXIT_FAILURE; }