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",
237 }
else if (max > 1) {
241 do_crm_log(error_level,
"Too many matches for %s in %s",
244 for (lpc = 0; lpc < max; lpc++) {
249 matchNodePath = (
char *) xmlGetNodePath(match);
251 xpath, lpc,
crm_str(matchNodePath));
270 int offset,
size_t buffer_size)
272 const char *
id =
ID(xml);
274 if(offset == 0 && prefix == NULL && xml->parent) {
280 offset += snprintf(buffer + offset, buffer_size - offset,
281 "/%s[@id='%s']", (
const char *) xml->name,
id);
282 }
else if(xml->name) {
283 offset += snprintf(buffer + offset, buffer_size - offset,
284 "/%s", (
const char *) xml->name);
297 return strdup(buffer);
310 if (node == NULL || xpath == NULL) {
315 start = strstr(xpath, patt);
322 start += strlen(patt);
325 end = strstr(start,
"\'");
327 retval =
strndup(start, end-start);
#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)
xmlDoc * getDocPtr(xmlNode *node)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
#define do_crm_log(level, fmt, args...)
Log a message.
#define crm_log_xml_explicit(xml, text)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int pcmk__element_xpath(const char *prefix, xmlNode *xml, char *buffer, int offset, size_t buffer_size)
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)
#define PCMK__BUFFER_SIZE
pcmk__action_result_t result
char * xml_get_path(xmlNode *xml)
#define crm_err(fmt, args...)