0

此示例的明显输出将是日期和时间。


在迭代文档的上下文中,该xml文档如何正确转换或转换为dotnet core on ?xmlPowershellLinux

PS /home/nicholas/flwor> 
PS /home/nicholas/flwor> Select-Xml -Xml (Get-Date | ConvertTo-Xml) -XPath "/Objects/Object"

Node   Path        Pattern
----   ----        -------
Object InputStream /Objects/Object

PS /home/nicholas/flwor> 
PS /home/nicholas/flwor> (Get-Date | ConvertTo-Xml).OuterXml                                
<?xml version="1.0" encoding="utf-8"?><Objects><Object Type="System.DateTime">12/10/2020 5:12:45 AM</Object></Objects>
PS /home/nicholas/flwor> 

用最简单的例子更新。

所以,这个例子是xml但是:它是如何用 xpath 解析或查询的?

IRC中给出的替代解决方案:

PS /home/nicholas/flwor> 
PS /home/nicholas/flwor> $date.SelectSingleNode('/Objects/Object').'#text'
12/10/2020 5:07:04 AM
PS /home/nicholas/flwor> 

毫无疑问,使用 and 是可行Select-XmlXpath

4

1 回答 1

0

如果尴尬,这有效:

PS /home/nicholas/flwor> 
PS /home/nicholas/flwor> Select-Xml -Xml (Get-Date | ConvertTo-Xml) -XPath "/Objects/Object" |  Select-Object -ExpandProperty Node

Type            #text
----            -----
System.DateTime 12/10/2020 5:23:39 AM

PS /home/nicholas/flwor> 

帮助文件有一个类似的例子。

于 2020-12-10T13:25:54.893 回答