简体   繁体   中英

Powershell XML Object not returned

I have an xml which looks like this

<?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)

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]$xmlfile = get-content $filename

That should solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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