I'm currently attempting to create a double-parented XML file within Python using minidom, however I'm struggling to get it to work (and by struggling I mean it's not)
I'm trying to create something like this:
<?xml version="1.0"?>
<twitter>
<account>
<name>Triple J</name>
<handle>triplejplays</handle>
<format>.{artist} - {title} [{time}]</format>
</account>
<account>
<name>BBC Radio 1</name>
<handle>BBCR1MusicBot</handle>
<format>Now Playing {artist} - {title}</format>
</account>
</twitter>
Using this code:
def createXML():
#Define document
xmlFile = Document()
#Create base element
baseElement = xmlFile.createElement("twitter")
#Create account element
accountElement = xmlFile.createElement("account")
#Append account element to base element
baseElement.appendChild(accountElement)
#Create elements and content under account
nameElement = xmlFile.createElement("name")
nameContent = xmlFile.createTextNode("Triple J")
nameContent.appendChild(nameElement)
nameElement.appendChild(accountElement)
handleElement = xmlFile.createElement("handle")
handleContent = xmlFile.createTextNode("triplejplays")
handleContent.appendChild(handleElement)
handleElement.appendChild(accountElement)
formatElement = xmlFile.createElement("format")
formatContent = xmlFile.createTextNode(".{artist} - {title} [{time}]")
formatContent.appendChild(formatElement)
formatElement.appendChild(formatElement)
print(doc.toxml(encoding='utf-8'))
createXML()
But I get this error:
Text nodes cannot have children
Is there any way to make this work? Thanks in advance!