user3325210
user3325210

Reputation: 163

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

Upvotes: 0

Views: 58

Answers (1)

TheMadTechnician
TheMadTechnician

Reputation: 36277

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.

Upvotes: 1

Related Questions