XML - empty elements handling.

Welcome Forums General PowerShell Q&A XML - empty elements handling.

This topic contains 0 replies, has 1 voice, and was last updated by  lsystems06 2 months, 1 week ago.

  • Author
    Posts
  • #165271

    Participant
    Topics: 2
    Replies: 2
    Points: 32
    Rank: Member

    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

    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.

You must be logged in to reply to this topic.