In my first class i parse my xml file like this :
class ListActeurs():
fonction_key = "DiagramElements"
def __init__(self):
self.list_acteurs = []
root = ElementTree.parse("D:\\Users\T0211254\MyApp\Bundle CUD-CAPELLA 431\melody\eclipse\workspace\XML2\XML2.aird").getroot()
for diagram in self.root:
if ListActeurs.diagramme_key in diagram.tag:
self.diagram_name = diagram.attrib.get('name')
self.diagram_id = diagram.get('{
http://www.omg.org/XMI}id')
self.dict_diagrams[self.diagram_name] = self.diagram_id
for owned in diagram:
if ListActeurs.acteur_key in owned.tag:
self.acteur_name = owned.attrib.get('name') # Récupération des noms des acteurs
self.acteur_id = owned.get('{
http://www.omg.org/XMI}id') # Récupération des id's des acteurs
print(self.acteur_name, '==>', self.acteur_id)
for elements in owned:
if ListActeurs.fonction_key in elements.tag:
self.fonctions_name = elements.attrib.get('name') # Récupération des noms des fonctions
self.fonctions_id = elements.get('{
http://www.omg.org/XMI}id') # Récupération des ID's des fonctions
self.data_fonctions = ElementTree.tostring(elements)
self.list_acteurs.append(Acteur(self.fonctions_name, self.fonctions_id, self.data_fonctions))
At the end i create an Object Acteur() with differents attributes including "self.data_fonction" which contains a part of the xml file in a String variable.
I would like to continue to parse this part of xml in another class. I tried this :
class Acteur() :
def __init__(self, fonctions_name, fonctions_id, data_fonctions):
self.fonctions_name = str(fonctions_name)
self.fonctions_id = str(fonctions_id)
self.data_fonctions = str(data_fonctions)
elements = ET.ElementTree(ET.fromstring(data_fonctions))
for ports in elements :
ports_name = ports.attrib.get('name')
print(ports_name)
But there is an error :
for ports in elements :
TypeError: 'ElementTree' object is not iterable
However I can't use the ElementTree fonction parse() because it's not anymore a file. How can i do that ? I have thinking of creating an xml file and to put "self.data_fonction" in it et to parse this xml file but is there any better method to do this ?
Thanks
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)