I have a XML document:
<Root>
<ItemA Name="1" />
<ItemB Name="2" />
<ItemC Name="3" />
</Root>
and a powershell script accessing data from that document. I need to iterate by the children of Root and print the element names of its children. Example:
$xml = [xml](gc MyXmlFile.xml);
$xml.Root.Name
# prints "Root"
$xml.Root.ChildNodes | foreach { $_.Name }
# prints 1 2 3 because Item(A|B|C) have an attribute named "Name"
# I need to print ItemA ItemB ItemC
Update: As MrKWatkins correctly pointed out below in this case I could use the LocalName property instead. However this will not work if I'm using namespaces of if I also have a LocalName attribute in my XML. I would like to know if exists a solution for this problem that always works no matter the XML file.