Hi all,

I need to transform the default namespace of a document to a prefixed
one. Is it ok to assign a string to the namespace, or do I need to
create a new namespace and replace it in the document?

This is the function I used to change the namespace:
        xmlDocPtr p = xmlParseFile( argv[ 1 ] );
        if( NULL == p )
        {
                fprintf( stderr, "Datei %s kann nicht geöffnet werden\n", argv[ 
1 ] );
                return 1;
        }
        xmlNodePtr root = xmlDocGetRootElement( p );
        assert( root );
        xmlNsPtr nsp = root->ns;
        while( NULL != nsp )
        {
                if ( NULL == nsp->prefix )
                {
                        nsp->prefix = xmlMemoryStrdup( "hc" );
                        break;
                }
                nsp = nsp->next;
        }
        if( NULL != nsp )
        {
                for( xmlNodePtr c = root->children; NULL != c; c = c->next )
                {
                        if ( XML_ELEMENT_NODE == c->type )
                        {
                                for( xmlAttrPtr p = c->properties; NULL != p; p 
= p->next )
                                {
                                        if( NULL == p->ns )
                                        {
                                                p->ns = nsp;
                                        }
                                }
                        }
                }
        }

TIA
Rudi

-- 
GPG encrypted mails preferred.
GPG verschlüsselte Mails bevorzugt.
---> http://chaosradio.ccc.de/media/ds/ds085.pdf Seite 20 <----
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to