41 int lpc, max = numXpathResults(xpathObj);
43 if (xpathObj == NULL) {
47 for (lpc = 0; lpc < max; lpc++) {
48 if (xpathObj->nodesetval->nodeTab[lpc] && xpathObj->nodesetval->nodeTab[lpc]->type != XML_NAMESPACE_DECL) {
49 xpathObj->nodesetval->nodeTab[lpc] = NULL;
54 xmlXPathFreeObject(xpathObj);
60 xmlNode *match = NULL;
61 int max = numXpathResults(xpathObj);
67 crm_err(
"Requested index %d of only %d items", index, max);
70 }
else if(xpathObj->nodesetval->nodeTab[index] == NULL) {
75 match = xpathObj->nodesetval->nodeTab[index];
78 if (xpathObj->nodesetval->nodeTab[index]->type != XML_NAMESPACE_DECL) {
80 xpathObj->nodesetval->nodeTab[index] = NULL;
83 if (match->type == XML_DOCUMENT_NODE) {
85 match = match->children;
87 }
else if (match->type != XML_ELEMENT_NODE
88 && match->parent && match->parent->type == XML_ELEMENT_NODE) {
90 match = match->parent;
92 }
else if (match->type != XML_ELEMENT_NODE) {
94 crm_err(
"We only support %d not %d", XML_ELEMENT_NODE, match->type);
103 int lpc, max = numXpathResults(xpathObj);
105 if (xpathObj == NULL) {
109 for (lpc = 0; lpc < max; lpc++) {
111 gboolean dedup = FALSE;
113 if (xpathObj->nodesetval->nodeTab[lpc] == NULL) {
117 xml = xpathObj->nodesetval->nodeTab[lpc]->parent;
119 for (; xml; xml = xml->parent) {
122 for (lpc2 = 0; lpc2 < max; lpc2++) {
123 if (xpathObj->nodesetval->nodeTab[lpc2] == xml) {
124 xpathObj->nodesetval->nodeTab[lpc] = NULL;
141 xmlXPathObjectPtr xpathObj = NULL;
142 xmlXPathContextPtr xpathCtx = NULL;
149 xpathCtx = xmlXPathNewContext(xml_top->doc);
152 xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
153 xmlXPathFreeContext(xpathCtx);
171 void (*helper)(xmlNode*,
void*),
void *user_data)
174 int nresults = numXpathResults(xpathObj);
177 for (i = 0; i < nresults; i++) {
182 (*helper)(
result, user_data);
192 char *xpath_full = NULL;
193 char *xpath_prefix = NULL;
195 if (xml_obj == NULL || xpath == NULL) {
199 xpath_prefix = (
char *)xmlGetNodePath(xml_obj);
215 xmlXPathObjectPtr xpathObj = NULL;
216 char *nodePath = NULL;
217 char *matchNodePath = NULL;
224 nodePath = (
char *)xmlGetNodePath(xml_obj);
225 max = numXpathResults(xpathObj);
229 do_crm_log(error_level,
"No match for %s in %s",
230 xpath, pcmk__s(nodePath,
"unknown path"));
234 }
else if (max > 1) {
238 do_crm_log(error_level,
"Too many matches for %s in %s",
239 xpath, pcmk__s(nodePath,
"unknown path"));
241 for (lpc = 0; lpc < max; lpc++) {
246 matchNodePath = (
char *) xmlGetNodePath(match);
249 pcmk__s(matchNodePath,
"unrecognizable match"));
280 const xmlNode *
parent = NULL;
281 GString *xpath = NULL;
282 const char *
id = NULL;
291 xpath = g_string_sized_new(256);
296 g_string_append_c(xpath,
'/');
297 }
else if (
parent->parent == NULL) {
298 g_string_append(xpath, (
const gchar *) xml->name);
319 if (node == NULL || xpath == NULL) {
324 start = strstr(xpath, patt);
331 start += strlen(patt);
334 end = strstr(start,
"\'");
336 retval = strndup(start, end-start);
363 if (g_path == NULL) {
367 path = strdup((
const char *) g_path->str);
370 g_string_free(g_path, TRUE);
#define CRM_CHECK(expr, failure_action)
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
void freeXpathObject(xmlXPathObjectPtr xpathObj)
xmlNode * get_xpath_object_relative(const char *xpath, xmlNode *xml_obj, int error_level)
#define CRM_LOG_ASSERT(expr)
Deprecated Pacemaker XML API.
#define do_crm_log(level, fmt, args...)
Log a message.
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
#define crm_log_xml_explicit(xml, text)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
char * xml_get_path(const xmlNode *xml)
Get an XPath string that matches an XML element as closely as possible.
const xmlChar * pcmkXmlStr
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
void dedupXpathResults(xmlXPathObjectPtr xpathObj)
char * pcmk__xpath_node_id(const char *xpath, const char *node)
pcmk__action_result_t result
#define crm_err(fmt, args...)
GString * pcmk__element_xpath(const xmlNode *xml)