In Powershell, how can I get the value of the .Name property of an XML element when it has a child node called 'Name' which masks the property.
# Assign XML that contains an element called 'Name' deliberately
# to mask the .Name property on the parent element.
$xml = [xml]@"
<People>
<Person>
<Name>Jo Bloggs</Name>
</Person>
</People>
"@
Write-Host $xml.People.FirstChild.Name
# > Jo Bloggs
#Expect to get the .Name property of the <Person> element but instead
# we get the 'Name' child node text.
# Use XML that doesn't mask the .Name property
$xml = [xml]@"
<People>
<Person>
<FullName>Jo Bloggs</FullName>
</Person>
</People>
"@
Write-Host $xml.People.FirstChild.Name
# > Person
# We now get what we originally expected, the value of the .Name
# property of the Person element itself.
Of course, I can call the .LocalName property of the Person element and I get the expected result, but that's not a generic solution as if the Person element has a LocalName child element, that too is masked.
UPDATE 2021-08-26 : I have since found this SO question which is very similar to mine, with some detailed answers. Unable to completely parse XML in powershell