Question on win_lineinfile replace/deleting the values with-in config file

Hello,

I have got a task to configure the config file by removing the not required text from the config file.

Sample Config File:

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

Text to Remove: ${time} ${level}

So far I was able to do this using the below win_lineinfile playbook and it works fine:

Hello,

I have got a task to configure the config file by removing the not required text from the config file.

Sample Config File:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
<variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}" />
<rules>
<logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
<logger minLevel="Info" writeTo="EventLog" />
</rules>
<targets>
<target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log"
layout="${time} ${level} ${message}" concurrentWrites="true" encoding="utf-8" writeBom="true" />
<target type="EventLog" name="EventLog" layout="${processname} ${assembly-version} ${newline}${message}"
log="Application" />
</targets>
</nlog>

Text to Remove: ${time} ${level}

So far I was able to do this using the below win_lineinfile playbook and it works fine:

---

- hosts: all

tasks:

- name: updating content in config file

 win\_lineinfile:

   dest: C:\\tmp\\NLog\.config

   regexp: &#39;^\(\.\*\)time\(\.\*\)$&#39;

   line: &#39;    &lt;target type=&quot;File&quot; name=&quot;WorkflowLogFiles&quot;

fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${message}" concurrentWrites="true"
encoding="utf-8" writeBom="true" />'

   backrefs: yes

I would like to know if there is a better way to handle this instead of re-writing the whole line, can I only
replace/delete the portion of the text?

Lineinfile doesn't make sense for XML files, use (win_)xml module.

Regards
         Racke