I'm using ElementTree API to read and write to an XML document. When I try to add a tag that starts with a number, the XML file is no longer valid. Using import xml.etree.cElementTree as ET
, I am successfully able to create the XML document, but when I try to read in the XML file again, I get a ParseError. For my purposes, it does not matter if the XML document is not well formed. I just need to be able to start a tag with a number. Any idea how to do this?
This is what I have tried:
from lxml import etree
parser = etree.XMLParser(recover=True)
tree = ET.parse('xmldoc.xml')
root = tree.getroot()
xmlstring = ET.tostring(root)
etree.fromstring(xmlstring, parser=parser)
If I use this, I get this error:
ValueError: Invalid tag name u'1.0'
after trying to do this:
inputowner = raw_input("Enter owner for " + ls[i] + ": ")
child = ET.SubElement(prev , ls[i], owner = inputowner)
prev = child
prevowner = inputowner
Here is the list I am trying to put into an XML file:
['components', 'rel', 'core.slpi', '1.0', 'blluuses', 'i2c', 'src', 'logs', 'I2cUlog.c']
Each item in the list should be used as the ElementTree tag. The problem arises when I reach '1.0'.
If unable to answer first question, do you know of any other module that will do virtually the same thing but allow me have a tag that starts with a number? ElementTree is fantastic, I just need this one thing to work and then I can move on.