Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportNode creates empty xmlns attribute

Regrading this code:

   var tmpNewNode = xdoc.ImportNode(newNode, true);

    if (oldNode.ParentNode != null)
    {
        oldNode.ParentNode.ReplaceChild(tmpNewNode, oldNode);
        return true;
    }

tmpNewNode is created with empty xmlns attribute (xmlns=""). Any suggestion how can I avoid it?

10x

like image 429
Guy Avatar asked Dec 02 '10 15:12

Guy


1 Answers

What's probably happening here is that newNode comes from a document with no namespace declared, but oldNode is in a document with a namespace. In this situation, the node takes its blank namespace over to the new document and it shows up explicitly. To be honest, if it's only a problem for a string comparison, it won't hurt to just remove all instances of xmlns="" from the XML string before you work with it.

like image 137
MarkXA Avatar answered Nov 07 '22 15:11

MarkXA