Your XML file isn't correct. You have two "RecordsExport" tags and the conversion to XML fails with this diagnostic:
Error: "Unexpected end of file has occurred. The following elements are not closed: RecordsExport. Line 16, position 18."
This version of the XML file corrects that:
<?xml version="1.0"?>
<RecordsExport xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RecordsExport>
<ResultSet>
<SRN>1</SRN>
<Name>Tom</Name>
<Gender>Male</Gender>
<ChangeDate xsi:nil="true" />
</ResultSet>
<ResultSet>
<SRN>2</SRN>
<Name>Jack</Name>
<Gender>Male</Gender>
<ChangeDate xsi:nil="true" />
</ResultSet>
</RecordsExport>
</RecordsExport>
This version of your script correctly casts the contents of the XML file as an "[xml]" object and adjusts the "ForEach" to account for the additional "RecordsExport" tag:
$xmldata = [xml](Get-Content -Path 'C:\junk\test.xml' -raw)
$import_data = foreach ($data in $xmldata.RecordsExport.RecordsExport.ResultSet) {
[PSCustomObject]@{
SRN = $data.SRN
ServiceID = $data.Name
Platform = $data.Gender
Domain = $data.ChangeDate
}
}
The results of running the script against the corrected file:
SRN ServiceID Platform Domain
--- --------- -------- ------
1 Tom Male ChangeDate
2 Jack Male ChangeDate