Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
826 views
in Technique[技术] by (71.8m points)

xml - How can you use PowerShell's . (dot) notation to walk through elements with periods in the element name?

PowerShell makes working with XML fairly easy in most cases. However, I'm having trouble using the "dot" notation to walk through a web.config file. Everything works

Import-Module WebAdministration
$site = get-website | ? { $_.name -eq "My Website - 80" }
$WebConfigFile = $site.physicalPath + "web.config"
[xml]$WebAppXml = Get-Content $WebConfigFile
$webAppXml.configuration.system.web

On the last line, PowerShell uses intellisense to fill in system.web, but if you try to run it, the output is null. I know I can use Xpath or the .NET Xml objects, but I'd rather not if I don't have to.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
$webAppXml.configuration.'system.web'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...