Would the following code snipet be correct (logic-wise)?

xmlNsPtr namespace=xmlDocGetRootElement(doc)->ns;
if(!xmlStrEqual(namespace->prefix,"xhtml"))
{
        if(!xmlDictExists(doc->dict,"xhtml"))
        {
                if(namespace->prefix)xmlFree(namespace->prefix);
                xmlChar *newPrefix=xmlMalloc(5);
                memcpy(newPrefix,"xhtml",5);
                namespace->prefix=newPrefix;
        }
}

Also, would the change apply to each child node automatically, or
would I have to walk through the tree and assign the new prefix in the
same manner?



On 1/13/06, Daniel Veillard <[EMAIL PROTECTED]> wrote:
> On Thu, Jan 12, 2006 at 11:31:43PM -0500, Krepis P. wrote:
> > I need to either set or change a prefix for a namespace on an existing
> > document tree. There's plenty of ways to get the information on the
> > namespace, but I'm not sure how best to change the namespace prefix.
> > Do I just assign a new xmlChar * to xmlNsPtr->prefix, or do I need to
> > use a function for that (or do anything else along with it)?
>
>   yes replace the prefix in the xmlNs. Check if it doesn't come from the
> document dictionnary, if no xmlFree() it, and then replace it by a new
> xmlMalloc'ed string or by a string from the dictionnary.
>   The operation has no public entry point, usually namespaces are immutable
> as the prefix should not be important and changing the namespace name affects
> all referencing nodes in the document.
>
> Daniel
>
> --
> Daniel Veillard      | Red Hat http://redhat.com/
> [EMAIL PROTECTED]  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
> http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
>
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to