【问题标题】:Accessing complex properties like "system.serviceModel" when using Powershell to parse xml [duplicate]使用 Powershell 解析 xml 时访问“system.serviceModel”等复杂属性 [重复]
【发布时间】:2011-07-26 03:21:59
【问题描述】:

可能重复:
How can you use PowerShell's . (dot) notation to walk through elements with periods in the element name?

我知道powershell会为XmlElements添加属性来简化对元素和属性的访问。

在解析 web.config 时,您会得到像“system.serviceModel”这样的元素。

当将 XmlElement 传递给 Get-member 时,我可以看到这是一个属性,但是当我尝试访问该属性时,我收到一条错误消息。

我认为这是因为引擎正在寻找一个名为 system 的属性,该属性具有一个名为 serviceModel 的属性,而不是一个名为“system.serviceModel”的属性

解析和访问这些元素的最佳方式是什么?

【问题讨论】:

  • 这样的问题已经很多了。希望人们在发布问题之前阅读建议

标签: xml powershell


【解决方案1】:

我现在没有要解析的 web.config 文件,但如果我理解问题是文件中存在一个名为 system.servicemodel 的节点。要访问这样的节点,您只需引用它。因此,如果您有一个代表该节点的父节点的变量 $xml,您可以通过以下方式访问它:

$xml.'system.servicemodel'

【讨论】:

  • 忘记了在任何 .net 框架安装中的几乎每个文件夹中都有一个 web.config(或者至少看起来是这样)。所以我检查了一下,正如我所说,如果我理解这个问题,那么这对我来说很好。
  • 谢谢。我知道这一定很简单
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 2011-01-16
  • 1970-01-01
  • 2017-04-23
  • 2013-01-17
相关资源
最近更新 更多