I've not explored working with XML side of Powershell yet. But, If it is only to generate an XML like you have given in example, i would propose a different approach, which will provide more flexibility.
You can create a csv file which will serve as the input for XML generating script, like:
Then the script will be
## Formatting The XML
$scriptblock = {
@"
<ns5:attributionRequest xmlns:ns2="http://www.ech.ch/xmlns/eCH-0011/3" xmlns="http://www.ech.ch/xmlns/eCH-0007/3" xmlns:ns4="http://www.ech.ch/xmlns/eCH-0010/3" xmlns:ns3="http://www.ech.ch/xmlns/eCH-0008/2" xmlns:ns5="http://www.ech.ch/xmlns/eCH-0083/1" xmlns:ns6="http://www.ech.ch/xmlns/eCH-0044/1" xmlns:ns7="http://www.ech.ch/xmlns/eCH-0090/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns8="http://www.ech.ch/xmlns/eCH-0006/2" xsi:schemaLocation="http://www.ech.ch/xmlns/eCH-0083/1 http://www.ech.ch/xmlns/eCH-0083/1/eCH-0083-1-1.xsd">
<ns5:header>
<ns5:senderId xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">$($_.type)</ns5:senderId>
</ns5:header>
<ns5:record>
<ns5:localPersonId>
<ns6:personIdCategory>$($_.personIdCategory)</ns6:personIdCategory>
<ns6:personId>$($_.personId)</ns6:personId>
</ns5:localPersonId>
<ns5:lastname>$($_.lastname)</ns5:lastname>
<ns5:firstNames>$($_.firstNames)</ns5:firstNames>
<ns5:birthDate>
<ns6:yearMonthDay>$($_.yearMonthDay)</ns6:yearMonthDay>
</ns5:birthDate>
<ns5:sex>$($_.sex)</ns5:sex>
<ns5:nationality>
<ns5:nationalityStatus>$($_.nationalityStatus)</ns5:nationalityStatus>
</ns5:nationality>
</ns5:record>
</ns5:attributionRequest>
"@
}
## Creating New XMLs
Import-csv .\file.csv | ForEach-Object{
$personId = $_.personId
& $scriptblock | out-file ".\$personId.xml"}
Put the csv and the script in same folder. This will generate XMLs with PersionId id,e.g., 10001.xml, 20001.xml in the same folder.
This way you can create N number of XMLs without actually editing the script.
Just keep adding the values in the CSV file.