# Updating XML inserts entity reference instead of left tag symbol

**URL:** <https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420>\
**Category:** PowerShell Help\
**Created:** [September 27, 2017, 11:57am UTC](https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420 "2017-09-27T11:57:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlanderos](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@mlanderos](https://forums.powershell.org/u/mlanderos)\
**Post date:** [September 27, 2017, 11:57am UTC](https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420/1 "2017-09-27T11:57:40Z")

</div>

Hi,

I am trying to update a value to a key within an XML document.

```
Add-Type -AssemblyName System.Web
$myValue= ""

$xml.SelectSingleNode("//configuration).value = $myValue
$xml.save($file)
```

But my XML document is saved with the entity reference “&l t;” instead of the left tag symbol (\<). I tried a number of different solutions to no avail. I cannot seem to escape it. My last possible solution was to add the HTMLDecode accelerator to hopefully keep the tags intact.

Any suggestions to overcome this?

---

<div class="post-metadata">

**Author:** ![exoblivione](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@exoblivione](https://forums.powershell.org/u/exoblivione)\
**Post date:** [September 27, 2017, 3:15pm UTC](https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420/2 "2017-09-27T15:15:06Z")

</div>

Here is a snippet from some code I used to update xml keys. I can explain if you like but basically it just replaces two key values. You can ignore the switch:

$key1 = “reportPath”  
$value1 = “C:\Folder Inventory Files\Folder Inventory Report.xlsx”  
$key2 = “failedLoanPath”  
$value2 = “C:\Folder Inventory Files\failed.txt”

New-Item “C:\Folder Inventory Files” -type directory

switch ($os) {

64-bit{

$config = “C:\Program Files (x86)\DocVelocity Folder Inventory Report\FolderInventoryReport.exe.config”  
$doc = New-Object System.Xml.XmlDocument  
$doc.Load($config)  
$node = $doc.SelectSingleNode(‘configuration/appSettings/add[@key="’ + $key1 + ‘"]’)  
$node.Attributes[‘value’].Value = $value1  
$node = $doc.SelectSingleNode(‘configuration/appSettings/add[@key="’ + $key2 + ‘"]’)  
$node.Attributes[‘value’].Value = $value2  
$doc.Save($config)

}

32-bit {

$config2 = “C:\Program Files\DocVelocity Folder Inventory Report\FolderInventoryReport.exe.config”  
$doc = New-Object System.Xml.XmlDocument  
$doc.Load($config2)  
$node = $doc.SelectSingleNode(‘configuration/appSettings/add[@key="’ + $key1 + ‘"]’)  
$node.Attributes[‘value’].Value = $value1  
$node = $doc.SelectSingleNode(‘configuration/appSettings/add[@key="’ + $key2 + ‘"]’)  
$node.Attributes[‘value’].Value = $value2  
$doc.Save($config2)

}

}

---

<div class="post-metadata">

**Author:** ![mlanderos](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@mlanderos](https://forums.powershell.org/u/mlanderos)\
**Post date:** [September 28, 2017, 10:05am UTC](https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420/3 "2017-09-28T10:05:34Z")

</div>

Thanks, Jim. I completely understand your code. However, my issue is different and I was unable to explain myself properly due to trying to expressed XML left and right tags without escaping them properly to properly show my issue.

My issue is that when I try to update a value for a key attribute within an XML document, for unknown reason it is save the document using it’s entity reference instead of the actual left/right tag symbol (left arrow or right arrow) instead I get (without spaces) & l t; and & r t;

Not sure why and trying to avoid that.

Any thoughts?

---

<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:37pm UTC](https://forums.powershell.org/t/updating-xml-inserts-entity-reference-instead-of-left-tag-symbol/9420/4 "2024-05-16T20:37:27Z")

</div>

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


