Remove unwanted (empty) xmlns attribute added by appendChild

后端 未结 6 1655
失恋的感觉
失恋的感觉 2020-12-18 18:32

I have this code:

function setupProject($projectFile) {
  [xml]$root = Get-Content $projectFile;

  $project = $root.Project;

  $beforeBuild = $root.CreateE         


        
6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 19:00

    The namespace is an inherent part of the name of each node.Removing namespace means need to recreate the node again. Here is the code, where you can create the child node without the Namespace property.

    [xml]$oXmlDocume = [xml] (Get-Content  D:\myXml.xml)
    // Assuming Project is the parent node
    $project = $oXMLDocument.Project
    $childNode = $oXMLDocument.CreateElement("Child",$project.NamespaceURI)
    $0XMLDocument.AppendChild($ChildNode)
    

    If you need to create the subchild under your child node, then follow the same style.

提交回复
热议问题