Why can't the xml created by this code be parsed by python or read?
I have a chunk of code that is writing an xml file:
idlist = list(set([d['type'] for d in List])) ##create list of all ID numbers idlist.sort() root = ET.Element("MarketData") for i in idlist: ##iterate over every ID number doc = ET.SubElement(root, 'Item', typeID=str(i)) ##create child for current ID number tList = list(filter(lambda x: x['type'] == i, List)) ##make a list of all orders for current ID sList = list(filter(lambda x: x['buy'] == False, tList)) ##create list of only sell orders bList = list(filter(lambda x: x['buy'] == True, tList)) ##create list of only by orders spl = list([d['price'] for d in sList]) ##create list of sell prices bpl = list([d['price'] for d in bList]) ##create list of buy prices if not spl: ##null case spl = [-1] if not bpl: ##null case bpl = [-1] sp = min(spl) ##find min sell price bp = max(bpl) ##find max buy price ET.SubElement(doc, 'Sell Price').text = str(sp) ##write sell price to child as string under new sub-element ET.SubElement(doc, 'Buy Price').text = str(bp) ##write buy price to branch as string under new sub-element tree = ET.ElementTree(root) tree.write("MarketData.xml") ##write xml tree to final xml file
it executes fine, and my test code with identical xml logic writes a perfectly readable file but when i create a file using this code it is unreadable and can't be parsed by ElementTree.
From python I get: "xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 41".
From Firefox i get: "error on line 1 at column 42: Specification mandate value for attribute Price".
The first chuck of the xml (when opened via np++) is:
<MarketData><Item typeID="18"><Sell Price>64.92</Sell Price><Buy Price>53.31</Buy Price></Item><Item typeID="19"><Sell Price>36999.99</Sell Price><Buy Price>3502.03</Buy Price></Item>
I'm at a complete loss... any suggestions?
note: I'm not a coder, I do this for fun while playing a game so please don't beat me up too hard for anything...