【发布时间】:2019-08-31 23:10:09
【问题描述】:
我有 XML 内容,我需要从节点的特定元素中删除整行。
XML 文件:
需要删除整行。
<Host name="login.net">
<Path name="Block">
<Path name="webservices/login" authType="qwerty" requireSession="true" />
<Path name="login" authType="qwerty" requireSession="true" />
<Path name="weblogin" requireSession="true" authType="shibboleth" />
</Path>
<Path name="retailpdf" applicationId="retailpdf" authType="qwerty" requireSession="true" requireSessionWith="retailpdf" />
<Path name="managemyaccount" applicationId="managemyaccount" authType="qwerty" requireSession="true" requireSessionWith="managemyaccount" />
<Path name="approve" applicationId="approve" authType="qwerty" requireSession="true" requireSessionWith="approve" />
<Path name="latesignin" applicationId="latesignin" authType="qwerty" requireSession="true" requireSessionWith="latesignin" />
<Path name="fblogin" applicationId="fblogin" authType="qwerty" requireSession="true" requireSessionWith="fblogin" />
</Host>
</RequestMap>
#需要删除id为retailpdf的完整节点
试图通过powershell脚本删除行
$XMLfilepath = 'C:\Test\MYfile.xml'
psedit $XMLfilepath
$Pathxml = [xml] (Get-Content $XMLfilepath)
$nodes = $xml.SelectNodes("/RequestMapper/Path");
{Remove-Item "<Path name="fblogin" applicationId="fblogin" authType="shibboleth" requireSession="true" requireSessionWith="fblogin" />"}
$XMLfilepathNew = 'C:\Test\Myfiledone.xml'
$Pathxml.Save($XMLfilepathNew)
psedit $XMLfilepathNew
需要删除 XML 内容中提到的行和节点,如下所示:
预期输出:
<Host name="login.net">
<Path name="Block">
<Path name="webservices/login" authType="qwerty" requireSession="true" />
<Path name="login" authType="qwerty" requireSession="true" />
<Path name="weblogin" requireSession="true" authType="shibboleth" />
</Path>
<Path name="managemyaccount" applicationId="managemyaccount" authType="qwerty" requireSession="true" requireSessionWith="managemyaccount" />
<Path name="approve" applicationId="approve" authType="qwerty" requireSession="true" requireSessionWith="approve" />
<Path name="latesignin" applicationId="latesignin" authType="qwerty" requireSession="true" requireSessionWith="latesignin" />
<Path name="fblogin" applicationId="fblogin" authType="qwerty" requireSession="true" requireSessionWith="fblogin" />
</Host>
</RequestMap>
<ApplicationOverride id="retailpdf" entityID="https://login.tcxqa.hrblock.net/retailpdf/shibboleth">
<Sessions lifetime="60" timeout="20" checkAddress="false" consistentAddress="false" handlerURL="/retailpdf/Shibboleth.sso" handlerSSL="true">
<SessionInitiator type="Chaining" Location="/retailpdf" isDefault="false" id="retailpdf" forceAuthn="true" entityID="https://qaidp.hrblock.net/idp/shibboleth" authnContextClassRef="urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport">
<SessionInitiator type="SAML2" template="bindingTemplate.html" />
</SessionInitiator>
</Sessions>
【问题讨论】:
-
#需要删除
整行。 -
#需要删除id为retailpdf的完整节点
标签: xml powershell