ImportNode creates empty xmlns attribute

后端 未结 6 1920
误落风尘
误落风尘 2021-02-20 08:34

Regrading this code:

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

    if (oldNode.ParentNode != null)
    {
        oldNode.ParentNode.ReplaceChild(tmpNe         


        
6条回答
  •  春和景丽
    2021-02-20 09:00

    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.

提交回复
热议问题