从.config文件中删除特定元素

发布于 2025-02-08 11:27:59 字数 3189 浏览 3 评论 0原文

我正在尝试从软件的配置文件中删除特定元素。它的格式类似于我以前可以解析的XML,但这一次似乎有所不同。由于它并没有真正包含任何敏感信息,因此我将在此处将配置文件放在我需要删除的元素中。对不起,很长的帖子。

<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
...
</sectionGroup>
</configSections>
<startup>
...
</startup>
<runtime>
...
</runtime>
<system.net>
...
</system.net>
<applicationSettings>
<SoD.Settings>
<!--  SpeechAnywhere Services (SAS) Server URL. 
            For the Nuance hosted SAS instance, use https://sas.nuancehdp.com/basic 
            For on-premise deployments specify a URL using the format (http|https)://your.server.instance:port/basic?mode=1  -->
<setting name="ServerURL" serializeAs="String">
...
</setting>
<!--  Organization token  -->
<setting name="OrganizationToken" serializeAs="String">
...
</setting>
<!--  Added Paragon Fix  -->
<setting name="RapidNavigationPrecisionTuning" serializeAs="String">
...
</setting>
<setting name="SupportedDomains" serializeAs="String">
...
</setting>
<setting name="SupportedAccounts" serializeAs="String">
...
</setting>
<!--  Please ensure that the microphones available to end users produce high quality sound. The list of microphones, 
      presented to users, should be short and limited to models recommended by Nuance or verified by you with the application. 
      If you have any questions, contact your Nuance Professional Services representative.  -->
<setting name="AllowedMicrophones" serializeAs="String">
...
</setting>
<!--  Languages in the IETF format. To present a list of available languages
                to the end user, specify all supported languages in the setting and separate them
                    with the pipe (|) character (for example, de-DE|en-US|sv-SE|nl-BE).  -->
<setting name="SupportedLanguages" serializeAs="String">
...
</setting>
<!--  Speech recognition topic(s). If you want to present a list of available speech recognition 
                 topics to the end user, specify all supported speech recognition topics in the setting and 
                   separate them with the pipe (|) character (for example, GeneralMedicine|Surgery).  -->
<setting name="SupportedTopics" serializeAs="String">
...
</setting>
<setting name="EULAHasBeenAcceptedByAllUsers" serializeAs="String">
...
</setting>
<!-- 
              Authentication (none/native/ldap/ldaplocal/trusted/sso/sso_adfs)
              none : No authentication (default)
              native : NMS Native 
              ldap : LDAP/AD
              ldaplocal : LDAP local authentication
              trusted : Trusted
              sso : SSO via Central Authentication
              sso_adfs : SSO via ADFS Authentication
               -->
<setting name="Authentication" serializeAs="String">
<value>trusted</value>
</setting>

我需要在最后删除“受信任的”值,但似乎无法找到一种找到它的方法。我仍然是所有这些。谢谢!

I am trying to remove a specific element from a piece of software's config file. It is formatted similar to an XML, which I have been able to parse before, but it seems to be a little different this time. As it doesn't really contain any sensitive info, I will just put the config file here up to the element I need to remove. Sorry for the long post.

<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
...
</sectionGroup>
</configSections>
<startup>
...
</startup>
<runtime>
...
</runtime>
<system.net>
...
</system.net>
<applicationSettings>
<SoD.Settings>
<!--  SpeechAnywhere Services (SAS) Server URL. 
            For the Nuance hosted SAS instance, use https://sas.nuancehdp.com/basic 
            For on-premise deployments specify a URL using the format (http|https)://your.server.instance:port/basic?mode=1  -->
<setting name="ServerURL" serializeAs="String">
...
</setting>
<!--  Organization token  -->
<setting name="OrganizationToken" serializeAs="String">
...
</setting>
<!--  Added Paragon Fix  -->
<setting name="RapidNavigationPrecisionTuning" serializeAs="String">
...
</setting>
<setting name="SupportedDomains" serializeAs="String">
...
</setting>
<setting name="SupportedAccounts" serializeAs="String">
...
</setting>
<!--  Please ensure that the microphones available to end users produce high quality sound. The list of microphones, 
      presented to users, should be short and limited to models recommended by Nuance or verified by you with the application. 
      If you have any questions, contact your Nuance Professional Services representative.  -->
<setting name="AllowedMicrophones" serializeAs="String">
...
</setting>
<!--  Languages in the IETF format. To present a list of available languages
                to the end user, specify all supported languages in the setting and separate them
                    with the pipe (|) character (for example, de-DE|en-US|sv-SE|nl-BE).  -->
<setting name="SupportedLanguages" serializeAs="String">
...
</setting>
<!--  Speech recognition topic(s). If you want to present a list of available speech recognition 
                 topics to the end user, specify all supported speech recognition topics in the setting and 
                   separate them with the pipe (|) character (for example, GeneralMedicine|Surgery).  -->
<setting name="SupportedTopics" serializeAs="String">
...
</setting>
<setting name="EULAHasBeenAcceptedByAllUsers" serializeAs="String">
...
</setting>
<!-- 
              Authentication (none/native/ldap/ldaplocal/trusted/sso/sso_adfs)
              none : No authentication (default)
              native : NMS Native 
              ldap : LDAP/AD
              ldaplocal : LDAP local authentication
              trusted : Trusted
              sso : SSO via Central Authentication
              sso_adfs : SSO via ADFS Authentication
               -->
<setting name="Authentication" serializeAs="String">
<value>trusted</value>
</setting>

I need to remove the 'Trusted' value at the very end, but cant seem to figure out a way to find it. I am still very new to all of this. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天生の放荡 2025-02-15 11:27:59

如果该值始终存在于其自己的线上,那么您不妨将其剪切而不是解析XML:

# element to remove
$string = '<value>trusted</value>'

# get all lines except the trusted element
$edited = Get-Content 'C:\path\to\file.config' | Where {$_ -NE $string}

# write back to file
$edited | Out-File 'C:\path\to\file.config'

If that value always exists on its own line, then you might as well just cut it rather than parse the xml:

# element to remove
$string = '<value>trusted</value>'

# get all lines except the trusted element
$edited = Get-Content 'C:\path\to\file.config' | Where {$_ -NE $string}

# write back to file
$edited | Out-File 'C:\path\to\file.config'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文