Exemple #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);
}
Exemple #2
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);
}