Vagharsh Kandilian Vagharsh Kandilian - 2 months ago 12x
PowerShell Question

casting to XML by default parsing HTML tags too

I have an XML document which contains this

<?xml version="1.0" encoding="UTF-8"?>
<description>Only applicable if &quot;server&quot; is set to default.</description>

$gcXML = Get-Content -Path "C:\temp.xml"
Write-Output $gcXML

are preserved in the code above, but not in the code below:

$xdoc = [xml] $gcXML

is being parsed as
, which I don't want. Output is:

Only applicable if "server" is set to default.

How can I preserve the


You might re-encode the string if that's what you need and you do not wish to (or cannot) change the XML content:

# Load the System.Web assembly
Add-Type -Assembly System.Web

Versions of PowerShell older than 5 may need additional parentheses surrounding a complex value: