ImportNode creates empty xmlns attribute

后端 未结 6 1937
误落风尘
误落风尘 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 08:51

    Along the lines of what MarkXA said:

    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.

    You could manipulate the String for the purpose of the comparison but the nodes in your DOM would not be namespace qualified correctly which could cause you problems later if you tried to use it.

    The correct solution would be to build newNode with the proper namespace qualification in the first place. By propery namespace qualification, I mean the namespaces used in the importing DOM.

提交回复
热议问题