# win\_xml module 'cannot call a method on a null-valued expression'

**URL:** <https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576>\
**Category:** Ansible Project\
**Created:** [March 31, 2020, 10:15pm UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576 "2020-03-31T22:15:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [March 31, 2020, 10:15pm UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576/1 "2020-03-31T22:15:35Z")

</div>

I have an JBoss domain.xml file im trying to manipulate with win\_xml:

`  
  
…

`

When I try to modify the heap size attribute above using win\_xml with this play:

- name: Test modifying XML  
win\_xml:  
path: e:\jboss-eap-6.4\XXXXXXX\configuration\domain.xml  
xpath: ‘/domain/server-groups/server-group/jvm/heap’

attribute: ‘size’  
fragment: ‘123m’  
type: attribute

However, I get an exception that looks like its coming from powershell "You cannot call a method on a null-valued expression

`  
“exception”: “You cannot call a method on a null-valued expression.\r\nAt line:204 char:5\r\n+ [bool]$add = !$node.HasAttribute($attribute) -Or ($node.$attribut …\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \r\n + CategoryInfo : InvalidOperation: (🙂 , ParentContainsErrorRecordException\r\n + FullyQualifiedErrorId : InvokeMethodOnNull\r\n\r\nScriptStackTrace:\r\nat , : line 204\r\n”,

“msg”: “Unhandled exception while executing module: You cannot call a method on a null-valued expression.”,  
“\_ansible\_no\_log”: false,  
“changed”: false

}  
`

Anyone see my problem? I checked the xpath using Notepad++ xml tools plugin and it seems correct. Scratchin my head

---

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [March 31, 2020, 11:12pm UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576/2 "2020-03-31T23:12:45Z")

</div>

I forgot to add, the domain tag is:

not just

if that’s relevant.

---

<div class="post-metadata">

**Author:** ![Dave\_York](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@Dave\_York](https://forum.ansible.com/u/Dave_York)\
**Post date:** [April 1, 2020, 1:27am UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576/3 "2020-04-01T01:27:03Z")

</div>

I figured this out. Turned out that my xml was using a different namespace? I had to follow guidance I found on stackoverflow:  
[https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath](https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath)

So my play now looks like this (and works):

tasks:

- name: Test modifying XML  
win\_xml:  
path: e:\jboss-eap-6.4\XXXXXXXXX\configuration\domain.xml  
xpath: ‘/_[local-name()=“domain”]/_[local-name()=“server-groups”]/_[local-name()=“server-group”]/_[local-name()=“jvm”]/\*[local-name()=“heap”]’  
attribute: ‘size’  
fragment: ‘123m’  
type: attribute

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 1, 2020, 5:18am UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576/4 "2020-04-01T05:18:01Z")

</div>

Hi

While that does work, it looks like the xpath expression is flattening too much with all those wildcards.

The correct way would be to provide the actual namespace, this is supported by the module:

[https://docs.ansible.com/ansible/latest/modules/xml\_module.html#parameter-namespaces](https://docs.ansible.com/ansible/latest/modules/xml_module.html#parameter-namespaces)

Dick

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [April 1, 2020, 6:13am UTC](https://forum.ansible.com/t/win-xml-module-cannot-call-a-method-on-a-null-valued-expression/32576/5 "2020-04-01T06:13:33Z")

</div>

Forget what I said - I misread. The win\_xml module doesn’t have a ‘namespaces’ option.  
I mixed it up with the regular xml module.
