Esempio n. 1
0
/**
 * Declare user-defined mapping between a URI and a namespace.
 */
static void
xfmt_prefix_declare(struct xfmt_pass2 *xp2, const char *uri, const char *prefix)
{
    nv_pair_t *nv;

    nv = nv_table_lookup(xp2->uri2prefix, uri);
    if (nv != NULL) {
        /*
         * Silently ignore the mapping if we already have seen an identical one
         * in the XML tree during the first pass.
         */

        if (strcmp(prefix, nv_pair_value_str(nv)) != 0) {
            g_carp("XFMT ignoring supplied prefix '%s' for '%s': "
                   "already saw '%s' in the tree", prefix, uri,
                   nv_pair_value_str(nv));
        }
    } else {
        /*
         * New mapping.
         */

        nv = nv_pair_make_static_str(uri, prefix);
        nv_table_insert_pair(xp2->uri2prefix, nv);
    }
}
Esempio n. 2
0
/**
 * Record a tree-defined mapping between a prefix and a namespace URI.
 */
static void
xfmt_prefix_record(struct xfmt_pass1 *xp1, const char *prefix, const char *uri)
{
    nv_pair_t *nv;

    /*
     * Our policy is to use one single prefix for a given namespace URI
     * throughout the document.  Although several prefixes could be used.
     * this is confusing to read and serves no value: a human will be mislead
     * into thinking the two namespaces are different because they carry
     * distinct prefixes, and a machine will not care about the prefix value.
     */

    nv = nv_table_lookup(xp1->uri2prefix, uri);
    if (nv != NULL) {
        /*
         * Silently ignore the mapping if we already have seen an identical one
         * in the XML tree.
         */

        if (strcmp(prefix, nv_pair_value_str(nv)) != 0) {
            g_carp("XFMT ignoring prefix '%s' for '%s': "
                   "already saw '%s' earlier in the tree", prefix, uri,
                   nv_pair_value_str(nv));
        }
    } else {
        /*
         * New mapping.
         */

        nv = nv_pair_make_static_str(uri, prefix);
        nv_table_insert_pair(xp1->uri2prefix, nv);
    }
}
Esempio n. 3
0
/**
 * Add namespace declaration to element.
 *
 * There must not be any ':' in the prefix string.
 * The prefix must not have been already declared locally.
 *
 * @param element		the element node
 * @param prefix		the shorthand prefix for the namespace
 * @param uri			the namespace URI
 */
void
xnode_add_namespace(xnode_t *element, const char *prefix, const char *uri)
{
	size_t uri_len;

	xnode_check(element);
	g_assert(XNODE_T_ELEMENT == element->type);
	g_assert(prefix != NULL);
	g_assert(uri != NULL);
	g_assert(NULL == strchr(prefix, ':'));

	if (NULL == element->u.e.ns)
		element->u.e.ns = nv_table_make(TRUE);

	/* Prefix must not be redeclared in the same element */
	g_assert(NULL == nv_table_lookup(element->u.e.ns, prefix));

	uri_len = strlen(uri);
	nv_table_insert(element->u.e.ns, prefix, uri, uri_len + 1);
}