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);
193 xmlXPathObjectPtr xpathObj = NULL;
194 char *nodePath = NULL;
195 char *matchNodePath = NULL;
202 nodePath = (
char *)xmlGetNodePath(xml_obj);
203 max = numXpathResults(xpathObj);
207 do_crm_log(error_level,
"No match for %s in %s",
208 xpath, pcmk__s(nodePath,
"unknown path"));
212 }
else if (max > 1) {
216 do_crm_log(error_level,
"Too many matches for %s in %s",
217 xpath, pcmk__s(nodePath,
"unknown path"));
219 for (lpc = 0; lpc < max; lpc++) {
224 matchNodePath = (
char *) xmlGetNodePath(match);
227 pcmk__s(matchNodePath,
"unrecognizable match"));
258 const xmlNode *
parent = NULL;
259 GString *xpath = NULL;
260 const char *
id = NULL;
269 xpath = g_string_sized_new(256);
274 g_string_append_c(xpath,
'/');
275 }
else if (
parent->parent == NULL) {
276 g_string_append(xpath, (
const gchar *) xml->name);
281 id = pcmk__xe_id(xml);
297 if (node == NULL || xpath == NULL) {
302 start = strstr(xpath, patt);
309 start += strlen(patt);
312 end = strstr(start,
"\'");
314 retval = strndup(start, end-start);
321 output_attr_child(xmlNode *child,
void *userdata)
325 out->
info(out,
" Value: %s \t(id=%s)",
327 pcmk__s(pcmk__xe_id(child),
"<none>"));
335 if (out == NULL ||
name == NULL || search == NULL ||
336 search->children == NULL) {
365 if (g_path == NULL) {
369 g_string_free(g_path, TRUE);
377 char *xpath_full = NULL;
378 char *xpath_prefix = NULL;
380 if (xml_obj == NULL || xpath == NULL) {
384 xpath_prefix = (
char *)xmlGetNodePath(xml_obj);
#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)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
Deprecated Pacemaker XML API.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#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
Wrappers for and extensions to libxml2.
xmlXPathObjectPtr xpath_search(const xmlNode *xml_top, const char *path)
#define pcmk__str_copy(str)
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
int pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name, int(*handler)(xmlNode *xml, void *userdata), void *userdata)
#define crm_err(fmt, args...)
#define pcmk__mem_assert(ptr)
This structure contains everything that makes up a single output formatter.
void pcmk__warn_multiple_name_matches(pcmk__output_t *out, xmlNode *search, const char *name)
GString * pcmk__element_xpath(const xmlNode *xml)