from MindMap import MindMapRoot

class XML2MindMapRoot:
  def createFromXML(self, xml_string):
    from xml.dom.minidom import parseString
    dom = parseString(xml_string)
    node = dom.childNodes[0]
    mmr = MindMapRoot()
    self.createFromXMLOne(mmr, node, None)
    return mmr

  def createFromXMLOne(self, mmr, node, parent_code):
    for childNode in node.childNodes:
      if childNode.nodeName == 'node':
        message = childNode._attrs['TEXT'].value.encode('utf-8')
        color = childNode._attrs['color'].value.encode('utf-8')
        child = mmr.add(parent_code, message)
        child.setColor(color) #
        self.createFromXMLOne(mmr, childNode, child.getCode())
