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 xmlDocPtr doc = NULL;
142 xmlXPathObjectPtr xpathObj = NULL;
143 xmlXPathContextPtr xpathCtx = NULL;
152 xpathCtx = xmlXPathNewContext(doc);
155 xpathObj = xmlXPathEvalExpression(xpathExpr, xpathCtx);
156 xmlXPathFreeContext(xpathCtx);
174 void (*helper)(xmlNode*,
void*),
void *user_data)
177 int nresults = numXpathResults(xpathObj);
180 for (i = 0; i < nresults; i++) {
185 (*helper)(
result, user_data);
195 char *xpath_full = NULL;
196 char *xpath_prefix = NULL;
198 if (xml_obj == NULL || xpath == NULL) {
202 xpath_prefix = (
char *)xmlGetNodePath(xml_obj);
218 xmlXPathObjectPtr xpathObj = NULL;
219 char *nodePath = NULL;
220 char *matchNodePath = NULL;
227 nodePath = (
char *)xmlGetNodePath(xml_obj);
228 max = numXpathResults(xpathObj);
232 do_crm_log(error_level,
"No match for %s in %s",
233 xpath, pcmk__s(nodePath,
"unknown path"));
237 }
else if (max > 1) {
241 do_crm_log(error_level,
"Too many matches for %s in %s",
242 xpath, pcmk__s(nodePath,
"unknown path"));
244 for (lpc = 0; lpc < max; lpc++) {
249 matchNodePath = (
char *) xmlGetNodePath(match);
252 pcmk__s(matchNodePath,
"unrecognizable match"));
283 const xmlNode *
parent = NULL;
284 GString *xpath = NULL;
285 const char *
id = NULL;
294 xpath = g_string_sized_new(256);
299 g_string_append_c(xpath,
'/');
300 }
else if (
parent->parent == NULL) {
301 g_string_append(xpath,
TYPE(xml));
322 if (node == NULL || xpath == NULL) {
327 start = strstr(xpath, patt);
334 start += strlen(patt);
337 end = strstr(start,
"\'");
339 retval =
strndup(start, end-start);
366 if (g_path == NULL) {
370 path = strdup((
const char *) g_path->str);
373 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)
char * strndup(const char *str, size_t len)
Deprecated Pacemaker XML API.
xmlDoc * getDocPtr(xmlNode *node)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#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
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)