有没有办法将字符串转换为XML标记或搜索XML文档?
我正在尝试根据输入的值编辑xml文档 我需要能够选择xml路径中要更改的变量有没有办法将字符串转换为XML标记或搜索XML文档?,xml,powershell,Xml,Powershell,我正在尝试根据输入的值编辑xml文档 我需要能够选择xml路径中要更改的变量 param( [Parameter()] [string]$xmlpath, [Parameter()] [string]$variable, [Parameter()] [string]$xmltag ) [xml]$c = Get-Content ./filename # I want to
param(
[Parameter()]
[string]$xmlpath,
[Parameter()]
[string]$variable,
[Parameter()]
[string]$xmltag
)
[xml]$c = Get-Content ./filename
# I want to have the path go something like this but strings won't work
$c.$xmlpath.$variable.$xmltag
我试过几种不同的方法。转换为XML。将输入参数创建为一个对象,并绑定ABC.DEF.GHI(xml路径)。
我还研究了selectxml,但无法在文档中按$variable进行筛选
有没有人经历过这个问题?如果是这样的话,你能给我指出正确的方向吗?应该可以,我使用了另一个问题中的一些XML进行测试
$XML =
[XML]@"
<monitor>
<fileProcessor>
<pathConfiguration>
<path>/path/to/file</path>
</pathConfiguration>
</fileProcessor>
</monitor>
"@
$monitor = 'monitor'
$FileProc= 'fileProcessor'
$path = 'path'
$config = 'pathConfiguration'
$xml.$monitor.$fileProc.$config.$path
应该可以,我使用了另一个问题中的一些XML进行测试
$XML =
[XML]@"
<monitor>
<fileProcessor>
<pathConfiguration>
<path>/path/to/file</path>
</pathConfiguration>
</fileProcessor>
</monitor>
"@
$monitor = 'monitor'
$FileProc= 'fileProcessor'
$path = 'path'
$config = 'pathConfiguration'
$xml.$monitor.$fileProc.$config.$path
可以使用XML示例。可以使用XML示例。工作非常出色!谢谢你的帮助!工作得很有魅力!谢谢你的帮助!