I'm new to Python and need a little advice on one of my project from the experts.
I have a xml file that i need to parse and then sort . Below is the example of the xml file
<Product_Key Name="Visio Professional 2002" KeyRetrievalNote="">
<Key ID=“XXX” Type="Static Activation Key">12345-67890</Key>
</Product_Key>
<Product_Key Name="Visio Professional 2008" KeyRetrievalNote="">
<Key ID=“XXX” Type="Static Activation Key">23456-78901</Key>
</Product_Key>
<Product_Key Name="Visio Professional 2012" KeyRetrievalNote="">
<Key ID=“XXX” Type="Static Activation Key">34567-89012</Key>
</Product_Key>
<Product_Key Name="Visio Professional 2016” KeyRetrievalNote="">
<Key ID=“XXX” Type="Static Activation Key">45678-90123</Key>
</Product_Key>
Below is the output that i'm trying to achieve
Visio Professional 2002: 12345-67890
Visio Professional 2008: 23456-78901
Visio Professional 2012: 34567-89012
Visio Professional 2016: 45678-90123
I'm trying to get the name of the product and in front of it the corresponding product key.
I can get the output like below however that is not what I'm looking for.
Visio Professional 2002
Visio Professional 2008
Visio Professional 2012
Visio Professional 2016
12345-67890
23456-78901
34567-89012
45678-90123
The snip of the code that i used is below .
import xml.dom.minidom
def main():
doc = xml.dom.minidom.parse("keysexport.xml")
names = doc.getElementsByTagName("Product_Key")
keys = doc.getElementsByTagName("Key")
for name in names:
print(name.getAttribute("Name"))
for key in keys:
print(key.firstChild.nodeValue)
if __name__ == "__main__":
main();