XML ファイルからコンテンツを取得する方法がわかりません。以下は、私のxmlファイルがどのように見えるかです。完全な「nlog」ノードを取得しようとしています。助けてください。
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, ..."/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="LoggingDirectory" value="D:/Logging/"/>
<include file="${LoggingDirectory}Config/Framework.nlog.xml"/>
</nlog>
</configuration>
これが私がこれまでに試したことです:
$nlogConfigFile = 'D:\machine.config.nlog.xml'
$nlogConfigXml = new-object xml
$nlogConfigXml.Load($nlogConfigFile);
$nlogConfigXml.PreserveWhitespace = $true
このブログで提供されている「Get-XmlNode」関数を使用しましたhttp://blog.danskingdom.com/powershell-functions-to-get-an-xml-node-and-get-and-set-an-xml-要素が存在しない場合でも、要素の値/
Get-XmlNode -XmlDocument $nlogConfigXml -NodePath "configuration.configSections.section[@name='nlog']" ## works OK
Get-XmlNode -XmlDocument $nlogConfigXml -NodePath "configuration.nlog" ## does NOT work
"Select-Xml" 、 .SelectSingleNode コマンドも試しましたが、どれも機能していないようです。何か不足している場合はお知らせください。