繁体   English   中英

在PowerShell中读取XML节点属性

[英]Read XML node attribute in PowerShell

我有一门课,很少有属性。 该类的构造函数获得一个字符串属性,其中xml字符串是从数据库clob列读取的。

#Powershell code
Class test
{
    [string]$prop1
    [int]$prop2
    test([string]$input)
    {
        $xml = [xml]$input
        $this.prop1 = $xml|Select-XML -XPath '/Properties/Property[@name="Validation"]'
        $this.prop2 = $xml|Select-XML -XPath '/Properties/Property[@name="Port"]'
    }
}

这是xml字符串的样子

<?xml version="1.0" encoding="UTF-8"?><properties>
  <property name="Validation" value="yes"/>
  <property name="Port" value="636"/>
</properties>

我正在尝试从XML文件检索节点属性。 问题在于构造函数没有为属性分配值。 我在下面的行中没有任何数据。

$xml|Select-XML -XPath '/Properties/Property[@name="Port"]'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM