小编jon*_*mes的帖子

如何使用PowerShell删除XML节点?

我正在努力寻找一种方法来删除这个节点:

<Mapping Key="pdf" Value="icpdf.gif"/>
Run Code Online (Sandbox Code Playgroud)

我在此主题的底部列出了XML文件.

这是我到目前为止所得到的.

这就是我正在运行的:

$xmlFile = “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML\docicon.xml” 
$xmlDoc = [XML](gc $xmlFile) 
$xml =[xml]'<DocIcons><ByExtension><Mapping Key ="pdf" Value = "icpdf"/></ByExtension></DocIcons>' 
$xml | Select-Xml -XPath '//Mapping' | ForEach-Object{$_.Node.RemoveAll()} 
$xmldoc.save("C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML\docicon.xml") 
$xml 
Run Code Online (Sandbox Code Playgroud)

任何帮助非常感谢:-)

docicon.xml:违规节点就在最后

<?xml version="1.0" encoding="utf-8"?> 
<DocIcons> 
<ByProgID> 
    <Mapping Key="Excel.Sheet" Value="ichtmxls.gif" EditText="Microsoft Office Excel" OpenControl="SharePoint.OpenDocuments" /> 
    <Mapping Key="FrontPage.Editor.Document" Value="ichtmfp.gif" EditText="Microsoft Office SharePoint Designer" OpenControl="SharePoint.OpenDocuments" /> 
    <Mapping Key="InfoPath.Document" Value="icxddoc.gif" EditText="Microsoft Office InfoPath" OpenControl="SharePoint.OpenXMLDocuments" /> 
    <Mapping Key="InfoPath.Document.2" Value="icxddoc.gif" EditText="Microsoft Office InfoPath" OpenControl="SharePoint.OpenXMLDocuments.2" /> …
Run Code Online (Sandbox Code Playgroud)

powershell xpath nodes

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

nodes ×1

powershell ×1

xpath ×1