I created a XML-Reader that creates a pretty stupid formated List, the script thats goint to use it needs it this way though.
import xml.etree.ElementTree as ET
PATH_IN = "<Path>\sweep.xml"
tree = ET.parse(PATH_IN)
root = tree.getroot()
Input = []
for project in root:
for design in project:
list_lvl2 = []
list_lvl2.append(project.get('name'))
list_lvl2.append(design.get('name'))
list_lvl2.append('')
list_lvl3 = []
for param in design:
list_lvl4 = []
list_lvl4.append(param.get('name'))
list_lvl5 = []
for steps in param:
list_lvl5.append(steps.text)
list_lvl4.append(list_lvl5)
list_lvl4.append(param.get('unit'))
list_lvl3.append(list_lvl4)
list_lvl2.append(list_lvl3)
Input.append(list_lvl2)
Problem is I have to execute it in the Scripting Interface of a Program which uses IronPython 2.6.10920.0 on .NET 2.0.50727.5466. And it throws following error:
*Global - Messages
[error] ImportException: No module named expat; use SimpleXMLTreeBuilder instead In file "<Path>/sweep.py", line 36 ---- While executing script: <Path>/sweep.py
[error] Error executing script in <Path>\sweep.py:
[error] ImportException: No module named expat; use SimpleXMLTreeBuilder instead In file "<Path>/sweep.py", line 36 ---- While executing script: <Path>/sweep.py
[error] Error executing script in <Path>\sweep.py:
What I don't understand is that this script which uses the same module works fine:
import xml.etree.ElementTree as ET
path = "<Path>\projects.xml"
root = ET.Element('xml')
projects = oDesktop.GetProjectList()
for i in projects:
project = ET.SubElement(root,'project')
project.set('name', i)
designs = oDesktop.SetActiveProject(i).GetTopDesignList()
for u in designs:
design = ET.SubElement(project,'design')
design.set('name', u)
vars = oDesktop.SetActiveProject(i).GetDesign(u).GetVariables()
for z in vars:
param = ET.SubElement(design,'param')
param.set('name', z)
value = ET.SubElement(param,'value')
value.text = oDesktop.SetActiveProject(i).GetDesign(u).GetVariableValue(z)
f = open(path, "w")
tree = ET.ElementTree(root)
tree.write(f)
f.close()
oDesktop and such are just programspecific functions that fetch data. I really don't understand why the first script won't work, I'm guessing because of NET 2.0.
UPDATE: After looking up what expat is, I'm even more confused since I never use it anywhere and all elementtree functions I use should be supported whith this version of Iron Python. Still it gives me the expat error on this line tree = ET.parse(PATH_IN)
UPDATE: I tried using from elementtree import SimpleXMLTreeBuilder as ET which resulted in:
*Global - Messages
[error] ImportException: No module named elementtree In file "<Path>/sweep.py", line 3 ---- While executing script: <Path>/sweep.py
[error] Error executing script in <Path>\sweep.py:
expatis used byElementTreeto parse the xml. Your other script is writing xml not parsing it, so there's no problem. It's still strange that you get this error, though. Maybe your IronPython install is broken? Try using another treebuilder, or even finding/making your own treebuilder using a .NET XML parser.