static int node_rm_attr(lua_State *L) { xmlNodePtr node = lua_touserdata(L, 1); const char *name = lua_tostring(L, 2); const char *ns_str = lua_tostring(L, 3); xmlNsPtr ns = NULL; int ret; if (node == NULL) return luaL_error(L, "rm_attribute: Invalid node"); if (node->type != XML_ELEMENT_NODE) return luaL_error(L, "rm_attribute: Invalid node type (not element node)"); if (name == NULL) return luaL_error(L, "rm_attribute: Specify attribute name"); if (ns_str != NULL) { ns = xmlSearchNsByHref(node->doc, node, BAD_CAST ns_str); if (ns == NULL) return luaL_error(L, "Namespace not defined yet."); } if (ns == NULL) { ret = xmlUnsetProp(node, BAD_CAST name); } else { ret = xmlUnsetNsProp(node, ns, BAD_CAST name); } /** * Boolean variable indicates TRUE as 1 and FALSE as 0 * xmlUnset*Prop returns O for OK and -1 for error * 0(ok) + 1 = 1(true) and -1(error) + 1 = 0(false) */ lua_pushboolean(L, ret+1); return 1; }
static int node_add_child(lua_State *L) { xmlNodePtr node = lua_touserdata(L, 1); const char *name = lua_tostring(L, 2); const char *ns_href = lua_tostring(L, 3); xmlNsPtr ns = NULL; if (node == NULL) return luaL_error(L, "add_child: Invalid parent node"); if (node->type != XML_ELEMENT_NODE) return luaL_error(L, "add_child: Invalid parent node type (not element node)"); if (name == NULL) return luaL_error(L, "I can't create node without its name"); xmlNodePtr child; if (ns_href != NULL) { //add namespace requested ns = xmlSearchNsByHref(node->doc, node, BAD_CAST ns_href); //try to find ns } if (ns_href != NULL && ns == NULL) { //ns requested and not found child = xmlNewChild(node, ns, BAD_CAST name, NULL); //crete node w/o ns ns = xmlNewNs(child, BAD_CAST ns_href, NULL); //create namespace and define it in child if (ns == NULL) return luaL_error(L, "Namespace allocation error."); xmlSetNs(child, ns); //set new ns to child } else { child = xmlNewChild(node, ns, BAD_CAST name, NULL); //ns nor requested ir was found... use it } lua_pushlightuserdata(L, child); luaL_setmetatable(L, WRAP_XMLNODE); return 1; }
/** * xsltGetSpecialNamespace: * @ctxt: a transformation context * @cur: the input node * @URI: the namespace URI * @prefix: the suggested prefix * @out: the output node (or its parent) * * Find the right namespace value for this URI, if needed create * and add a new namespace decalaration on the node * * Returns the namespace node to use or NULL */ xmlNsPtr xsltGetSpecialNamespace(xsltTransformContextPtr ctxt, xmlNodePtr cur, const xmlChar *URI, const xmlChar *prefix, xmlNodePtr out) { xmlNsPtr ret; static int prefixno = 1; char nprefix[10]; if ((ctxt == NULL) || (cur == NULL) || (out == NULL) || (URI == NULL)) return(NULL); if ((out->parent != NULL) && (out->parent->type == XML_ELEMENT_NODE) && (out->parent->ns != NULL) && (xmlStrEqual(out->parent->ns->href, URI))) ret = out->parent->ns; else ret = xmlSearchNsByHref(out->doc, out, URI); if (ret == NULL) { if (prefix == NULL) { do { sprintf(nprefix, "ns%d", prefixno++); ret = xmlSearchNs(out->doc, out, (xmlChar *)nprefix); } while (ret != NULL); prefix = (const xmlChar *) &nprefix[0]; } if (out->type == XML_ELEMENT_NODE) ret = xmlNewNs(out, URI, prefix); } return(ret); }
static int node_set_attr(lua_State *L) { xmlNodePtr node = lua_touserdata(L, 1); const char *name = lua_tostring(L, 2); const char *value = lua_tostring(L, 3); const char *ns_str = lua_tostring(L, 4); xmlNsPtr ns = NULL; if (node == NULL) return luaL_error(L, "set_attribute: Invalid node"); if (node->type != XML_ELEMENT_NODE) return luaL_error(L, "set_attribute: Invalid node type (not element node)"); if (name == NULL) return luaL_error(L, "set_attribute: Specify attribute name"); if (value == NULL) return luaL_error(L, "set_attribute: Specify attribute value"); if (ns_str != NULL) { ns = xmlSearchNsByHref(node->doc, node, BAD_CAST ns_str); if (ns == NULL) return luaL_error(L, "Namespace not registered yet."); if (ns->prefix == NULL) return luaL_error(L, "Namespace has not registered prefix."); } if (ns == NULL) { xmlSetProp(node, BAD_CAST name, BAD_CAST value); } else { xmlSetNsProp(node, ns, BAD_CAST name, BAD_CAST value); } lua_pushlightuserdata(L, node); luaL_setmetatable(L, WRAP_XMLNODE); return 1; }
xmlNode *oscap_reference_to_dom(struct oscap_reference *ref, xmlNode *parent, xmlDoc *doc, const char *elname) { if (!ref) return NULL; xmlNode *ref_node = xmlNewChild(parent, NULL, BAD_CAST elname, NULL); if (ref->href != NULL) xmlNewProp(ref_node, BAD_CAST "href", BAD_CAST ref->href); if (!ref->is_dublincore) { xmlNodeAddContent(ref_node, BAD_CAST ref->title); return ref_node; } xmlNs *ns_dc = xmlSearchNsByHref(doc, parent, NS_DUBLINCORE); if (ns_dc == NULL) // the namespace hasn't been defined in ancestor elements ns_dc = xmlNewNs(ref_node, NS_DUBLINCORE, BAD_CAST "dc"); DC_ITEM_TO_DOM(title); DC_ITEM_TO_DOM(creator); DC_ITEM_TO_DOM(subject); DC_ITEM_TO_DOM(description); DC_ITEM_TO_DOM(publisher); DC_ITEM_TO_DOM(contributor); DC_ITEM_TO_DOM(date); DC_ITEM_TO_DOM(type); DC_ITEM_TO_DOM(format); DC_ITEM_TO_DOM(identifier); DC_ITEM_TO_DOM(source); DC_ITEM_TO_DOM(language); DC_ITEM_TO_DOM(relation); DC_ITEM_TO_DOM(coverage); DC_ITEM_TO_DOM(rights); return ref_node; }
/** * gnumeric_xml_read_format_template_category : * Open an XML file and read a FormatTemplateCategory */ static FormatTemplateCategory * gnumeric_xml_read_format_template_category (char const *dir_name) { gchar *file_name; xmlDocPtr doc; xmlNodePtr node; FormatTemplateCategory *category = NULL; g_return_val_if_fail (dir_name != NULL, NULL); file_name = g_build_filename (dir_name, ".category", NULL); doc = xmlParseFile (file_name); if (doc != NULL && doc->xmlRootNode != NULL && xmlSearchNsByHref (doc, doc->xmlRootNode, (xmlChar *)"http://www.gnome.org/gnumeric/format-template-category/v1") != NULL && strcmp (CXML2C (doc->xmlRootNode->name), "FormatTemplateCategory") == 0 && (node = go_xml_get_child_by_name (doc->xmlRootNode, "Information")) != NULL) { xmlChar *name = xmlGetProp (node, (xmlChar *)"name"); if (name != NULL) { xmlChar *description = xmlGetProp (node, (xmlChar *)"description"); category = g_new (FormatTemplateCategory, 1); category->directory = g_strdup (dir_name); category->name = g_strdup ((gchar *)name); category->description = g_strdup ((gchar *)description); category->is_writable = (access (dir_name, W_OK) == 0); if (description != NULL) xmlFree (description); xmlFree (name); } } xmlFreeDoc (doc); g_free (file_name); return category; }
static void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */ { xmlNsPtr nsptr, nsdftptr, curns, prevns = NULL; if (nodep->type == XML_ELEMENT_NODE) { /* Following if block primarily used for inserting nodes created via createElementNS */ if (nodep->nsDef != NULL) { curns = nodep->nsDef; while (curns) { nsdftptr = curns->next; if (curns->href != NULL) { if((nsptr = xmlSearchNsByHref(doc, nodep->parent, curns->href)) && (curns->prefix == NULL || xmlStrEqual(nsptr->prefix, curns->prefix))) { curns->next = NULL; if (prevns == NULL) { nodep->nsDef = nsdftptr; } else { prevns->next = nsdftptr; } dom_set_old_ns(doc, curns); curns = prevns; } } prevns = curns; curns = nsdftptr; } } xmlReconciliateNs(doc, nodep); } }
static void data_to_xml_cb (gpointer key, gpointer value, gpointer user_data) { struct data_to_xml_data *cb_data = user_data; CongNodePtr new_node; g_assert (cb_data->parent_node); g_assert (cb_data->make_node_callback); new_node = cb_data->make_node_callback (cb_data->parent_node->doc, value); xmlAddChild (cb_data->parent_node, new_node); if (key) { xmlNsPtr ns; ns = xmlSearchNsByHref (cb_data->parent_node->doc, new_node, XML_XML_NAMESPACE); if (ns == NULL) { g_warning ("FIXME couldn't find namespace %s ", XML_XML_NAMESPACE); } xmlSetNsProp (new_node, ns, (const xmlChar*)"lang", key); } }
/* * Extend the existing value for an attribute, appending the given value. */ static void slaxNodeAttribExtend (slax_data_t *sdp, xmlNodePtr nodep, const char *attrib, const char *value, const char *uri) { const xmlChar *uattrib = (const xmlChar *) attrib; xmlChar *current = uri ? xmlGetProp(nodep, uattrib) : xmlGetNsProp(nodep, uattrib, (const xmlChar *) uri); int clen = current ? xmlStrlen(current) + 1 : 0; int vlen = strlen(value) + 1; unsigned char *newp = alloca(clen + vlen); if (newp == NULL) { xmlParserError(sdp->sd_ctxt, "%s:%d: out of memory", sdp->sd_filename, sdp->sd_line); return; } if (clen) { memcpy(newp, current, clen - 1); newp[clen - 1] = ' '; xmlFree(current); } memcpy(newp + clen, value, vlen); if (uri == NULL) xmlSetProp(nodep, uattrib, newp); else { xmlNsPtr nsp = xmlSearchNsByHref(sdp->sd_docp, nodep, (const xmlChar *) uri); xmlSetNsProp(nodep, nsp, uattrib, newp); } }
std::string XMLNode::NamespacePrefix(const char *urn) { if (node_ == NULL) return ""; xmlNsPtr ns_ = xmlSearchNsByHref(node_->doc, node_, (const xmlChar*)urn); if (!ns_) return ""; return (char*)(ns_->prefix); }
void RL::Presentity::edit_presentity_form_submitted (bool submitted, Ekiga::Form &result) { if (!submitted) return; const std::string new_name = result.text ("name"); const std::string new_uri = result.text ("uri"); const std::set<std::string> new_groups = result.editable_set ("groups"); std::map<std::string, xmlNodePtr> future_group_nodes; xmlNsPtr ns = xmlSearchNsByHref (node->doc, node, BAD_CAST "http://www.ekiga.org"); bool reload = false; robust_xmlNodeSetContent (node, &name_node, "name", new_name); if (uri != new_uri) { xmlSetProp (node, (const xmlChar*)"uri", (const xmlChar*)uri.c_str ()); boost::shared_ptr<Ekiga::PresenceCore> presence_core(services.get<Ekiga::PresenceCore> ("presence-core")); presence_core->unfetch_presence (uri); reload = true; } for (std::map<std::string, xmlNodePtr>::const_iterator iter = group_nodes.begin (); iter != group_nodes.end () ; iter++) { if (new_groups.find (iter->first) == new_groups.end ()) { xmlUnlinkNode (iter->second); xmlFreeNode (iter->second); } else { future_group_nodes[iter->first] = iter->second; } } for (std::set<std::string>::const_iterator iter = new_groups.begin (); iter != new_groups.end (); iter++) { if (std::find (groups.begin (), groups.end (), *iter) == groups.end ()) future_group_nodes[*iter] = xmlNewChild (node, ns, BAD_CAST "group", BAD_CAST robust_xmlEscape (node->doc, *iter).c_str ()); } group_nodes = future_group_nodes; groups = new_groups; save (reload); }
void oval_message_to_dom(struct oval_message *message, xmlDoc * doc, xmlNode * tag_parent) { if (message) { xmlNs *ns_syschar = xmlSearchNsByHref(doc, tag_parent, OVAL_SYSCHAR_NAMESPACE); xmlNode *tag_message = xmlNewTextChild (tag_parent, ns_syschar, BAD_CAST "message", BAD_CAST oval_message_get_text(message)); xmlNewProp(tag_message, BAD_CAST "level", BAD_CAST oval_message_level_text(oval_message_get_level(message))); } }
static xmlNsPtr _soap_addressing_get_namespace(xmlNodePtr node) { xmlNsPtr ns; if (!(ns = xmlSearchNsByHref(node->doc, node, BAD_CAST WSA_NAMESPACE))) { ns = xmlNewNs(node, BAD_CAST WSA_NAMESPACE, BAD_CAST WSA_NAMESPACE_PREFIX); } return ns; }
xmlNs *lookup_xsi_ns(xmlDoc *doc) { // Look-up xsi namespace pointer. We can be pretty sure that this namespace // is defined in root element, because it usually carries xsi:schemaLocation // attribute. xmlNsPtr ns_xsi = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), OSCAP_XMLNS_XSI); if (ns_xsi == NULL) { ns_xsi = xmlNewNs(xmlDocGetRootElement(doc), OSCAP_XMLNS_XSI, BAD_CAST "xsi"); } return ns_xsi; }
const XMLNs *XMLElement::getNamespaceByHref(const char *href) const { xmlNs *ns = xmlSearchNsByHref(doc.getRealDocument(), node, (const xmlChar *)href); XMLObject *obj = scope->getXMLObjectFromLibXMLPtr(ns); if (obj) { return static_cast < XMLNs * >(obj); } return new XMLNs(*this, ns); }
xmlNode *oval_result_test_to_dom(struct oval_result_test *rslt_test, xmlDocPtr doc, xmlNode * parent) { __attribute__nonnull__(rslt_test); xmlNs *ns_results = xmlSearchNsByHref(doc, parent, OVAL_RESULTS_NAMESPACE); xmlNode *test_node = xmlNewTextChild(parent, ns_results, BAD_CAST "test", NULL); struct oval_test *oval_test = oval_result_test_get_test(rslt_test); char *test_id = oval_test_get_id(oval_test); xmlNewProp(test_node, BAD_CAST "test_id", BAD_CAST test_id); char version[10]; *version = '\0'; snprintf(version, sizeof(version), "%d", oval_test_get_version(oval_test)); xmlNewProp(test_node, BAD_CAST "version", BAD_CAST version); oval_existence_t existence = oval_test_get_existence(oval_test); if (existence != OVAL_AT_LEAST_ONE_EXISTS) { xmlNewProp(test_node, BAD_CAST "check_existence", BAD_CAST oval_existence_get_text(existence)); } oval_check_t check = oval_test_get_check(oval_test); xmlNewProp(test_node, BAD_CAST "check", BAD_CAST oval_check_get_text(check)); int instance_val = oval_result_test_get_instance(rslt_test); if (instance_val > 1) { char instance[10]; *instance = '\0'; snprintf(instance, sizeof(instance), "%d", instance_val); xmlNewProp(test_node, BAD_CAST "variable_instance", BAD_CAST instance); } oval_result_t result = oval_result_test_get_result(rslt_test); xmlNewProp(test_node, BAD_CAST "result", BAD_CAST oval_result_get_text(result)); /* does not make sense to report these when test(definition) is not evaluated */ if( result != OVAL_RESULT_NOT_EVALUATED) { struct oval_result_item_iterator *items = oval_result_test_get_items(rslt_test); while (oval_result_item_iterator_has_more(items)) { struct oval_result_item *item = oval_result_item_iterator_next(items); oval_result_item_to_dom(item, doc, test_node); } oval_result_item_iterator_free(items); struct oval_variable_binding_iterator *bindings = oval_result_test_get_bindings(rslt_test); while (oval_variable_binding_iterator_has_more(bindings)) { struct oval_variable_binding *binding = oval_variable_binding_iterator_next(bindings); _oval_result_binding_to_dom(binding, doc, test_node); } oval_variable_binding_iterator_free(bindings); } return test_node; }
xmlNs *lookup_xccdf_ns(xmlDoc *doc, xmlNode *parent, const struct xccdf_version_info *version_info) { assert(parent != NULL); xmlNs *ns_xccdf = xmlSearchNsByHref(doc, parent, (const xmlChar *)xccdf_version_info_get_namespace_uri(version_info)); if (ns_xccdf == NULL) { ns_xccdf = xmlNewNs(parent, (const xmlChar *) xccdf_version_info_get_namespace_uri(version_info), NULL); } return ns_xccdf; }
/* :nodoc: */ static void relink_namespace(xmlNodePtr reparented) { xmlNodePtr child; /* Avoid segv when relinking against unlinked nodes. */ if(!reparented->parent) return; /* Make sure that our reparented node has the correct namespaces */ if(!reparented->ns && reparented->doc != (xmlDocPtr)reparented->parent) xmlSetNs(reparented, reparented->parent->ns); /* Search our parents for an existing definition */ if(reparented->nsDef) { xmlNsPtr curr = reparented->nsDef; xmlNsPtr prev = NULL; while(curr) { xmlNsPtr ns = xmlSearchNsByHref( reparented->doc, reparented->parent, curr->href ); /* If we find the namespace is already declared, remove it from this * definition list. */ if(ns && ns != curr) { if (prev) { prev->next = curr->next; } else { reparented->nsDef = curr->next; } nokogiri_root_nsdef(curr, reparented->doc); } else { prev = curr; } curr = curr->next; } } /* Only walk all children if there actually is a namespace we need to */ /* reparent. */ if(NULL == reparented->ns) return; /* When a node gets reparented, walk it's children to make sure that */ /* their namespaces are reparented as well. */ child = reparented->children; while(NULL != child) { relink_namespace(child); child = child->next; } }
int f_manage_input_xml(const char *p_name,int s_type,audiovideo_t *p_audiovideo) { static xmlDocPtr p_doc; xmlNodePtr p_node; xmlNsPtr ns; if (s_type) //read the file from p_name { p_doc = xmlParseFile(p_name); p_node = xmlDocGetRootElement(p_doc); if (p_node == NULL) { xmlFreeDoc(p_doc); tc_log_error(__FILE__,"Invalid file format"); return(-1); } ns = xmlSearchNsByHref(p_doc, p_node, (const xmlChar *) "http://www.w3.org/2001/SMIL20/Language"); if (ns == NULL) { xmlFreeDoc(p_doc); tc_log_error(__FILE__,"Invalid Namespace"); return(-1); } ns = xmlSearchNs(p_doc, p_node, (const xmlChar *) "smil2"); if (ns == NULL) { xmlFreeDoc(p_doc); tc_log_error(__FILE__,"Invalid Namespace"); return(-1); } if (xmlStrcmp(p_node->name, (const xmlChar *) "smil")) { xmlFreeDoc(p_doc); tc_log_error(__FILE__,"Invalid Namespace"); return(-1); } f_delete_unused_node(p_node); memset(p_audiovideo,'\0',sizeof(audiovideo_t)); if(f_parse_tree(p_node,p_audiovideo)) return(1); if (f_complete_tree(p_audiovideo)) return(1); } else { f_free_tree(p_audiovideo); xmlFreeDoc(p_doc); } return(0); }
void oval_sysent_to_dom(struct oval_sysent *sysent, xmlDoc * doc, xmlNode * parent) { struct oval_record_field_iterator *rf_itr; xmlNsPtr ent_ns = parent->ns; xmlNodePtr root_node = xmlDocGetRootElement(doc); xmlNode *sysent_tag = NULL; char *tagname = oval_sysent_get_name(sysent); char *content = oval_sysent_get_value(sysent); bool mask = oval_sysent_get_mask(sysent); /* omit the value in oval_results if mask=true */ if (mask && !xmlStrcmp(root_node->name, BAD_CAST OVAL_ROOT_ELM_RESULTS)) { sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST ""); } else { sysent_tag = xmlNewTextChild(parent, ent_ns, BAD_CAST tagname, BAD_CAST content); } if (mask) { xmlNewProp(sysent_tag, BAD_CAST "mask", BAD_CAST "true"); } oval_datatype_t datatype_index = oval_sysent_get_datatype(sysent); if (datatype_index != OVAL_DATATYPE_STRING) { xmlNewProp(sysent_tag, BAD_CAST "datatype", BAD_CAST oval_datatype_get_text(datatype_index)); } oval_syschar_status_t status_index = oval_sysent_get_status(sysent); if (status_index != SYSCHAR_STATUS_EXISTS) { xmlNewProp(sysent_tag, BAD_CAST "status", BAD_CAST oval_syschar_status_get_text(status_index)); } rf_itr = oval_sysent_get_record_fields(sysent); if (oval_record_field_iterator_has_more(rf_itr)) { xmlNsPtr field_ns = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE); if (field_ns == NULL) { field_ns = xmlNewNs(xmlDocGetRootElement(doc), OVAL_SYSCHAR_NAMESPACE, NULL); } while (oval_record_field_iterator_has_more(rf_itr)) { struct oval_record_field *rf; rf = oval_record_field_iterator_next(rf_itr); oval_record_field_to_dom(rf, mask, doc, sysent_tag, field_ns); } } oval_record_field_iterator_free(rf_itr); }
static void ds_rds_add_relationship(xmlDocPtr doc, xmlNodePtr relationships, const char* type, const char* subject, const char* ref) { xmlNsPtr core_ns = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), BAD_CAST core_ns_uri); // create relationship between given request and the report xmlNodePtr relationship = xmlNewNode(core_ns, BAD_CAST "relationship"); xmlSetProp(relationship, BAD_CAST "type", BAD_CAST type); xmlSetProp(relationship, BAD_CAST "subject", BAD_CAST subject); xmlNodePtr ref_node = xmlNewNode(core_ns, BAD_CAST "ref"); xmlNodeSetContent(ref_node, BAD_CAST ref); xmlAddChild(relationship, ref_node); xmlAddChild(relationships, relationship); }
static void _oval_result_binding_to_dom(struct oval_variable_binding *binding, xmlDocPtr doc, xmlNode *parent) { xmlNs *ns_results = xmlSearchNsByHref(doc, parent, OVAL_RESULTS_NAMESPACE); struct oval_variable *oval_variable = oval_variable_binding_get_variable(binding); char *variable_id = oval_variable_get_id(oval_variable); struct oval_string_iterator *str_itr; str_itr = oval_variable_binding_get_values(binding); while (oval_string_iterator_has_more(str_itr)) { char *value; xmlNode *binding_node; value = oval_string_iterator_next(str_itr); binding_node = xmlNewTextChild(parent, ns_results, BAD_CAST "tested_variable", BAD_CAST value); xmlNewProp(binding_node, BAD_CAST "variable_id", BAD_CAST variable_id); } oval_string_iterator_free(str_itr); }
int exclude_namespace(elcgen *gen, expression *expr, const char *uri) { int found = 0; expression *xp; if (!strcmp(uri,XSLT_NS)) return 1; for (xp = expr; xp && !found; xp = xp->parent) { char *str; if (xp->xmlnode->ns && !strcmp((char*)xp->xmlnode->ns->href,XSLT_NS)) str = xmlGetNsProp(xp->xmlnode,"exclude-result-prefixes",NULL); else str = xmlGetNsProp(xp->xmlnode,"exclude-result-prefixes",XSLT_NS); if (str) { int end = 0; char *start = str; char *c; for (c = str; !found && !end; c++) { end = ('\0' == *c); if (end || isspace(*c)) { if (c > start) { xmlNsPtr ns; *c = '\0'; if (!strcmp(start,"#all")) { found = (NULL != xmlSearchNsByHref(gen->parse_doc,xp->xmlnode,(xmlChar*)uri)); } else if (!strcmp(start,"#default")) { found = ((NULL != xp->xmlnode->ns) && !strcmp((char*)xp->xmlnode->ns->href,uri)); } else { ns = xmlSearchNs(gen->parse_doc,xp->xmlnode,(xmlChar*)start); found = ((NULL != ns) && !strcmp((char*)ns->href,uri)); } } start = c+1; } } free(str); } } return found; }
void XMLAttr::setAttributeValue(xmlNode * node, const char *prefix, const char *name, const char *value) { if (node && node->type == XML_ELEMENT_NODE) { xmlAttr *attrs = 0; for (xmlAttr * cur = node->properties; cur; cur = cur->next) { if (cur->ns && !strcmp(name, (const char *)cur->name) && (!strcmp(prefix, (const char *)cur->ns->prefix) || !strcmp(prefix, (const char *)cur->ns->href))) { attrs = cur; break; } } if (attrs) { xmlSetNsProp(node, attrs->ns, (const xmlChar *)name, (const xmlChar *)value); } else { xmlNs *ns = 0; if (!strncmp(prefix, "http://", strlen("http://"))) { ns = xmlSearchNsByHref(node->doc, node, (const xmlChar *)prefix); } else { ns = xmlSearchNs(node->doc, node, (const xmlChar *)prefix); } if (ns) { xmlSetNsProp(node, ns, (const xmlChar *)name, (const xmlChar *)value); } else { xmlSetProp(node, (const xmlChar *)name, (const xmlChar *)value); } } } }
xmlNode *oval_state_content_to_dom(struct oval_state_content * content, xmlDoc * doc, xmlNode * parent) { __attribute__nonnull__(content); struct oval_record_field_iterator *rf_itr; bool parent_mask; xmlNode *content_node = oval_entity_to_dom(content->entity, doc, parent); parent_mask = oval_entity_get_mask(content->entity); rf_itr = oval_state_content_get_record_fields(content); if (oval_record_field_iterator_has_more(rf_itr)) { xmlNsPtr field_ns = NULL; field_ns = xmlSearchNsByHref(doc, xmlDocGetRootElement(doc), OVAL_DEFINITIONS_NAMESPACE); if (field_ns == NULL) { field_ns = xmlNewNs(xmlDocGetRootElement(doc), OVAL_DEFINITIONS_NAMESPACE, BAD_CAST "oval-def"); } while (oval_record_field_iterator_has_more(rf_itr)) { struct oval_record_field *rf; rf = oval_record_field_iterator_next(rf_itr); oval_record_field_to_dom(rf, parent_mask, doc, content_node, field_ns); } } oval_record_field_iterator_free(rf_itr); oval_check_t var_check = oval_state_content_get_var_check(content); if (var_check != OVAL_CHECK_ALL || xmlHasProp(content_node, BAD_CAST "var_ref")) xmlNewProp(content_node, BAD_CAST "var_check", BAD_CAST oval_check_get_text(var_check)); oval_check_t ent_check = oval_state_content_get_ent_check(content); if (ent_check != OVAL_CHECK_ALL) xmlNewProp(content_node, BAD_CAST "entity_check", BAD_CAST oval_check_get_text(ent_check)); oval_schema_version_t ver = oval_definition_model_get_core_schema_version(content->model); if (oval_schema_version_cmp(ver, OVAL_SCHEMA_VERSION(5.11.1)) >= 0) { oval_existence_t check_existence = oval_state_content_get_check_existence(content); if (check_existence != OVAL_AT_LEAST_ONE_EXISTS) { // at_least_one_exists is default value xmlNewProp(content_node, BAD_CAST "check_existence", BAD_CAST oval_existence_get_text(check_existence)); } } return content_node; }
/* * static gint validate_deletion(RADContext *ctxt) * * Validates a rasta file to be added to the toplevel tree. It * sets the pointers to the screen nodes and to the PATHINSERT node. */ static gint validate_deletion(RADContext *ctxt) { xmlNodePtr cur; g_return_val_if_fail(ctxt != NULL, -EINVAL); g_return_val_if_fail(ctxt->delta.doc != NULL, -EINVAL); cur = xmlDocGetRootElement(ctxt->delta.doc); g_assert(cur != NULL); ctxt->delta.ns = xmlSearchNsByHref(ctxt->delta.doc, cur, RASTA_NAMESPACE); g_assert(ctxt->delta.ns != NULL); cur = cur->children; while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { if ((xmlStrcmp(cur->name, "SCREENDELETE") == 0) && (ctxt->delta.screens == NULL)) { if (cur->ns != ctxt->delta.ns) return(-ESRCH); else ctxt->delta.screens = cur; } if ((xmlStrcmp(cur->name, "PATHDELETE") == 0) && (ctxt->delta.path == NULL)) { if (cur->ns != ctxt->delta.ns) return(-ESRCH); else if (ctxt->delta.path == NULL) ctxt->delta.path = cur; } } cur = cur->next; } if ((ctxt->delta.screens == NULL) && (ctxt->delta.path == NULL)) return(-ESRCH); return(0); } /* validate_deletion() */
xmlNode *oval_result_definition_to_dom (struct oval_result_definition * definition, oval_result_directive_content_t content, xmlDocPtr doc, xmlNode * parent) { xmlNs *ns_results = xmlSearchNsByHref(doc, parent, OVAL_RESULTS_NAMESPACE); xmlNode *definition_node = xmlNewTextChild(parent, ns_results, BAD_CAST "definition", NULL); struct oval_definition *oval_definition = oval_result_definition_get_definition(definition); char *definition_id = oval_definition_get_id(oval_definition); xmlNewProp(definition_node, BAD_CAST "definition_id", BAD_CAST definition_id); oval_result_t result = oval_result_definition_get_result(definition); const char *result_att = oval_result_get_text(result); xmlNewProp(definition_node, BAD_CAST "result", BAD_CAST result_att); int version = oval_definition_get_version(oval_definition); char version_att[10] = ""; snprintf(version_att, sizeof(version_att), "%d", version); xmlNewProp(definition_node, BAD_CAST "version", BAD_CAST version_att); int instance = oval_result_definition_get_instance(definition); if (instance != 1 || oval_result_definition_get_variable_instance_hint(definition) != instance) { char instance_att[10] = ""; snprintf(instance_att, sizeof(instance_att), "%d", instance); xmlNewProp(definition_node, BAD_CAST "variable_instance", BAD_CAST instance_att); } struct oval_message_iterator *messages = oval_result_definition_get_messages(definition); while (oval_message_iterator_has_more(messages)) { oval_message_to_dom(oval_message_iterator_next(messages), doc, definition_node); } oval_message_iterator_free(messages); if (content == OVAL_DIRECTIVE_CONTENT_FULL) { struct oval_result_criteria_node *criteria = oval_result_definition_get_criteria(definition); if (criteria) { oval_result_criteria_node_to_dom(criteria, doc, definition_node); } } return definition_node; }
/** * e_soap_message_get_namespace_prefix: * @msg: the #ESoapMessage. * @ns_uri: the namespace URI. * * Returns the namespace prefix for @ns_uri (or an empty string if * @ns_uri is set to the default namespace) * * Returns: The namespace prefix, or %NULL if no namespace exists * for the URI given. * * Since: 2.92 */ const gchar * e_soap_message_get_namespace_prefix (ESoapMessage *msg, const gchar *ns_uri) { ESoapMessagePrivate *priv; xmlNsPtr ns = NULL; g_return_val_if_fail (E_IS_SOAP_MESSAGE (msg), NULL); priv = E_SOAP_MESSAGE_GET_PRIVATE (msg); g_return_val_if_fail (ns_uri != NULL, NULL); ns = xmlSearchNsByHref (priv->doc, priv->last_node, (const xmlChar *) ns_uri); if (ns) { if (ns->prefix) return (const gchar *) ns->prefix; else return ""; } return NULL; }
int xsdInitObjModule (xmlNodePtr xsdNode) { xmlChar *tns = NULL; xmlNsPtr ns; if (xsdNode != NULL) tns = xmlGetProp (xsdNode, (const xmlChar *) "targetNamespace"); if (tns == NULL) { objInitModule (NULL); } else { ns = xmlSearchNsByHref (xsdNode->doc, xsdNode, tns); if (ns == NULL) { fprintf (stderr, "WARNING: Target namespace not found!\n"); return 0; } if (ns->prefix == NULL) { fprintf (stderr, "WARNING: Target namespace not found!\n"); return 0; } fprintf (stdout, "Target namespace ('%s') prefix: '%s'\n", tns, ns->prefix); objInitModule (ns->prefix); } return 1; }
xmlNodePtr ds_rds_create_report(xmlDocPtr target_doc, xmlNodePtr reports_node, xmlDocPtr source_doc, const char* report_id) { xmlNsPtr arf_ns = xmlSearchNsByHref(target_doc, xmlDocGetRootElement(target_doc), BAD_CAST arf_ns_uri); xmlNodePtr report = xmlNewNode(arf_ns, BAD_CAST "report"); xmlSetProp(report, BAD_CAST "id", BAD_CAST report_id); xmlNodePtr report_content = xmlNewNode(arf_ns, BAD_CAST "content"); xmlAddChild(report, report_content); xmlDOMWrapCtxtPtr wrap_ctxt = xmlDOMWrapNewCtxt(); xmlNodePtr res_node = NULL; xmlDOMWrapCloneNode(wrap_ctxt, source_doc, xmlDocGetRootElement(source_doc), &res_node, target_doc, NULL, 1, 0); xmlAddChild(report_content, res_node); xmlDOMWrapReconcileNamespaces(wrap_ctxt, res_node, 0); xmlDOMWrapFreeCtxt(wrap_ctxt); xmlAddChild(reports_node, report); return report; }