I'm executing a PS script to read the contents of an xml, update few tag values and store contents into multiple xml files. I'm able to achieve all this but the xml files created are not getting read properly by the messaging queue to which it is passed. BUT the same xml file works in the queue when I open it and click save without making any changes to the data. I compared the 2 files 1 - after it is created and 2 - after I open the same and click save and they are identical! I cannot for the life of me figure out what is going wrong and how to fix it.
How to create an output xml file in a readable format? Not sure what changes when I click 'Save' on the xml files. Please help.
input CASH.XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns:POSTransaction xmlns:ns="http://schema.xyz.com/Commerce/Customer/Transaction/v1">
<ns:tranHeader>
<ns:transactionId>96846836238236142669</ns:transactionId>
<ns:businessDateTime>2021-12-25T01:10:00</ns:businessDateTime>
<ns:emailId>Perftesting002@ymail.com</ns:emailId>
</ns:tranHeader>
</ns:POSTransaction>
PS:
$log="H:\logs.txt"
[xml]$loadXML = Get-Content "H:\Q_This\CASH.XML"
try
{
$tranID = $loadXML.POSTransaction.tranHeader.transactionId.substring(17,3)
$tranIntID = [int]$tranID
$tranc = $loadXML.POSTransaction.tranHeader.transactionId.substring(0,17)
$uname = $loadXML.POSTransaction.tranHeader.emailId.substring(0,11)
$mailcnt = [int]$loadXML.POSTransaction.tranHeader.emailId.substring(11,3)
$mailend = $loadXML.POSTransaction.tranHeader.emailId.Split("@")[1]
for ($mailcnt; $mailcnt -lt 10; $mailcnt++)
{
for ([int]$i =1; $i -le 5; $i++)
{
$mailupd = ([string]($mailcnt+1)).PadLeft(3,'0')
$tranIntID = $tranIntID+1
$loadXML.POSTransaction.tranHeader.transactionId = $tranc+[string]$tranIntID
$loadXML.POSTransaction.tranHeader.emailId = $uname+$mailupd+'@'+$mailend
$fileName = "CASH_"+$tranIntID+"_"+$mailupd+".XML"
$loadXML.Save("H:\Q_This\"+$fileName)
}
}
}
catch
{
Write-Host $_.Exception.Message
Add-content $log -value ([string](Get-Date) + ' ' +$_.Exception.Message)
}
The above code created 40 output xml files: 5 transaction files for each emailID from Performancetest003-010@ymail.com. However none of it was recognised by the messaging queue until I opened and clicked save (with no data change).