简体   繁体   English

Powershell XML对象未返回

[英]Powershell XML Object not returned

I have an xml which looks like this 我有一个看起来像这样的xml

<?xml version="1.0" encoding="utf-8" ?>

<objects xmlns="http:www.springframework.net">

<object id="id1" type="1" method="1">    
   <property name="name" ref="serv1"/>    
</object>

<object id="id2" type="2" method="2">    
  <property name="name2" ref="serv2"/>    
</object>

</objects>

Now when i do this in power shell 现在当我在电源外壳中执行此操作时

$xmlFile=get-content $filename

$xmlFile.selectNodes("/objects/object[@id='id1']")

it does not return anything (returns null) 它不返回任何内容(返回null)

I need to modify the property value for one of the objects. 我需要修改对象之一的属性值。 any help is welcome.Thanks 欢迎任何帮助。谢谢

You just need to define that it is an XML object, so change the first line to: 您只需要定义它是一个XML对象,因此将第一行更改为:

[xml]$xmlfile = get-content $filename

That should solve your problem. 那应该解决您的问题。

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

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