win_xml module 'cannot call a method on a null-valued expression'

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: (:slight_smile: , 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

I forgot to add, the domain tag is:

not just

if that’s relevant.

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

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

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

Dick

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.