【发布时间】:2014-04-16 00:14:26
【问题描述】:
任务是将以下xml代码读回Powershell并仅显示具有属性的项目:event="1"。
xml file created by Powershell script createsim.ps1
<?xml version="1.0" encoding="utf-8"?>
<simulation name="Protocal Simulation">
<duration type="clock">100000</duration>
<density>1.1</density>
<ideal_degree>12</ideal_degree>
<radius>86</radius>
<supportedchannels>[1,4,7,9,11,13]</supportedchannels>
<class>Field.RandomField</class>
<width>1000</width>
<height>1000</height>
<description event="1">Re-form the network</description>
<action event="1">densityChangeDetected()</action>
<description event="2">End the simulation</description>
<action event="2">end()</action>
</simulation>"
脚本的管道输出和导出对象。
PS C:\scripts> C:\scripts\createsim.ps1 | Export-Clixml C:\scripts\simtemp.xml
正在导入对象。
PS C:\scripts> $simxml = Import-Clixml C:\scripts\simtemp.xml
寻找事件属性。
PS C:\scripts> $xmlout = $simxml | Where-Object ($_.event -eq 1) | Sort-Object event
PS C:\scripts> $xmlout
PS C:\scripts> write-host $xmlout
没有错误消息,也没有打印出来。
如果有任何帮助或提示,我将不胜感激。我在 Windows 8.1 上使用 Powershell 4.0
【问题讨论】:
-
您确定在 Windows 8.1 上使用 PowerShell 2.0 吗?
-
抱歉是第4版
标签: xml powershell