+ /* Part 2, handle PluginInstanceFrom */
+ instance_node_obj = NULL;
+ instance_node = NULL;
+
+ /* plugin_instance_from has to be an xpath expression */
+ if (xpath->plugin_instance_from != NULL) {
+ instance_node_obj =
+ cx_evaluate_xpath(xpath_ctx, xpath->plugin_instance_from);
+ if (instance_node_obj == NULL)
+ return -1; /* error is already logged */
+
+ instance_node = instance_node_obj->nodesetval;
+ int tmp_size = (instance_node) ? instance_node->nodeNr : 0;
+
+ if (tmp_size <= 0) {
+ WARNING("curl_xml plugin: "
+ "relative xpath expression for 'PluginInstanceFrom' \"%s\" "
+ "doesn't match any of the nodes. Skipping the node.",
+ xpath->plugin_instance_from);
+ xmlXPathFreeObject(instance_node_obj);
+ return -1;
+ }
+
+ if (tmp_size > 1) {
+ WARNING("curl_xml plugin: "
+ "relative xpath expression for 'PluginInstanceFrom' \"%s\" "
+ "is expected to return only one text node. Skipping the node.",
+ xpath->plugin_instance_from);
+ xmlXPathFreeObject(instance_node_obj);
+ return -1;
+ }
+
+ /* ignoring the element if other than textnode/attribute */
+ if (cx_if_not_text_node(instance_node->nodeTab[0])) {
+ WARNING("curl_xml plugin: "
+ "relative xpath expression \"%s\" is expected to return only "
+ "text node which is not the case. Skipping the node.",
+ xpath->plugin_instance_from);
+ xmlXPathFreeObject(instance_node_obj);
+ return -1;
+ }
+
+ if (instance_node != NULL) {
+ char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]);
+ sstrncpy(vl->plugin_instance, node_value, sizeof(vl->plugin_instance));
+ sfree(node_value);
+ }
+
+ /* Free `instance_node_obj' this late, because `instance_node' points to
+ * somewhere inside this structure. */
+ xmlXPathFreeObject(instance_node_obj);
+ } /* if (xpath->plugin_instance_from != NULL) */
+