# XML - empty elements handling.

**URL:** <https://forums.powershell.org/t/xml-empty-elements-handling/12846>\
**Category:** PowerShell Help\
**Created:** [July 11, 2019, 2:40am UTC](https://forums.powershell.org/t/xml-empty-elements-handling/12846 "2019-07-11T02:40:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsystems](https://avatars.discourse-cdn.com/v4/letter/l/ba8739/32.png) [@lsystems](https://forums.powershell.org/u/lsystems)\
**Post date:** [July 11, 2019, 2:40am UTC](https://forums.powershell.org/t/xml-empty-elements-handling/12846/1 "2019-07-11T02:40:02Z")

</div>

Hi all,

I am writing my first Powershell script to modify an XML configuration file that I have no control over the format. It has empty elements listed as follows:-

[https://gist.github.com/langdonsystems/cc218075ca4e322429a3f17451d62dd9](https://gist.github.com/langdonsystems/cc218075ca4e322429a3f17451d62dd9)

If I simply open the above XML document and save it as follows:-

```
$xml = [xml](Get-Content "xmltest.xml")
$xml.save("$pwd\xmltest.xml.new")
```

Then the empty TEST element is now split over 2 lines now. Unfortunately this then causes issues with the program which then consumes this XML file (again which I have no control over). Is there anyway to prevent Powershell from doing this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/xml-empty-elements-handling/12846/2 "2024-05-16T20:32:00Z")

</div>

Closed on May 16, 2024, 8:32pm UTC


