Пример #1
0
//####################################################################
xml::ns xml::attributes::attr::set_namespace (const xml::ns &name_space) {
    if (name_space.is_void()) {
        erase_namespace();
        return xml::attributes::createUnsafeNamespace(NULL);
    }

    convert();
    xmlAttrPtr prop = reinterpret_cast<xmlAttrPtr>(normalize());

    if (!name_space.is_safe()) {
        prop->ns = reinterpret_cast<xmlNs*>(getUnsafeNamespacePointer(name_space));
    }
    else {
        const char *    prefix(name_space.get_prefix());
        if (prefix[0] == '\0')
            prefix = NULL;
        xmlNs *  definition(xmlSearchNs(NULL, reinterpret_cast<xmlNode*>(xmlnode_),
                                              reinterpret_cast<const xmlChar*>(prefix)));
        if (!definition)
            throw xml::exception("Namespace definition is not found");
        if (!xmlStrEqual(definition->href, reinterpret_cast<const xmlChar*>(name_space.get_uri())))
            throw xml::exception("Namespace definition URI differs to the given");
        prop->ns = definition;
    }
    return createUnsafeNamespace(prop->ns);
}
Пример #2
0
//####################################################################
xml::ns xml::node::add_namespace_definition (const xml::ns &name_space, ns_definition_adding_type type) {
    if (name_space.is_void()) throw xml::exception("void namespace cannot be added to namespace definitions");
    if (!pimpl_->xmlnode_->nsDef)   return add_namespace_def(name_space.get_uri(), name_space.get_prefix());

    // Search in the list of existed
    const char *    patternPrefix(name_space.get_prefix());
    if (patternPrefix[0] == '\0') patternPrefix = NULL;

    xmlNs *         current(pimpl_->xmlnode_->nsDef);
    while (current) {
        if (current->prefix == NULL) {
            // Check if the default namespace matched
            if (patternPrefix == NULL) return add_matched_namespace_def(current, name_space.get_uri(), type);
        }
        else {
            // Check if a non default namespace matched
            if (xmlStrEqual(reinterpret_cast<const xmlChar*>(patternPrefix), current->prefix))
                return add_matched_namespace_def(current, name_space.get_uri(), type);
        }
        current = current->next;
    }

    // Not found in the existed, so simply add the namespace
    return add_namespace_def(name_space.get_uri(), name_space.get_prefix());
}
Пример #3
0
//####################################################################
xml::ns xml::node::set_namespace (const xml::ns &name_space) {
    if (name_space.is_void()) {
        erase_namespace();
        // The erase_namespace updates the node->ns pointer approprietly
        return xml::ns(pimpl_->xmlnode_->ns);
    }
    if (!name_space.is_safe()) {
        pimpl_->xmlnode_->ns = reinterpret_cast<xmlNs*>(name_space.unsafe_ns_);
    }
    else {
        const char *    prefix(name_space.get_prefix());
        if (prefix[0] == '\0') prefix = NULL;

        xmlNs *  definition(xmlSearchNs(NULL, pimpl_->xmlnode_, reinterpret_cast<const xmlChar*>(prefix)));
        if (!definition)
            throw xml::exception("Namespace definition is not found");
        if (!xmlStrEqual(definition->href, reinterpret_cast<const xmlChar*>(name_space.get_uri())))
            throw xml::exception("Namespace definition URI differs to the given");
        pimpl_->xmlnode_->ns = definition;
    }
    return xml::ns(pimpl_->xmlnode_->ns);
}