Parsing XML files in Noesis

Coders and would-be coders alike, this is the place to talk about programming.
Post Reply
errno
n00b
Posts: 12
Joined: Sun Oct 05, 2014 12:08 am
Has thanked: 22 times
Been thanked: 2 times

Parsing XML files in Noesis

Post by errno » Sat Jun 18, 2016 2:59 am

There's certain data for the models I am currently working on that is stored in XML files. I am using one of Python's provided XML parsers to handle them like this:

Code: Select all

import xml.etree.ElementTree as etree

#a few lines later:
tree = etree.parse(xmlFilePath)
root = tree.getroot()
However, the code above causes Noesis to stop running the script, saying:

Code: Select all

Traceback (most recent call last):
  File "C:\noesis\plugins\python\core321.zip\xml\etree\ElementTree.py", line 1488, in __init__
  File "C:\noesis\plugins\python\core321.zip\xml\parsers\expat.py", line 6, in <module>
ImportError: No module named pyexpat
Now, to the best of my knowledge, Noesis includes the core libraries for parsing XML, so I am unsure why it's failing. I would really wish to avoid reinventing the wheel by parsing the XML files myself. Does anyone know what would be the best way to parse XML files inside Noesis scripts?

I'm using the latest version of Noesis (v4.177)

User avatar
chrrox
Moderator
Posts: 2512
Joined: Sun May 18, 2008 3:01 pm
Has thanked: 57 times
Been thanked: 1244 times

Re: Parsing XML files in Noesis

Post by chrrox » Sat Jun 18, 2016 6:25 am

from xml.dom.minidom import parseString


datasource = open(matFileName)
data = datasource.read()
dom = parseString(data)
soup = BeautifulSoup(datasource, 'xml')
tree = ET.parse('D:/Games/Data/materials.xml')
print(tree.getroot())

datasource.close()

you can try this.

errno
n00b
Posts: 12
Joined: Sun Oct 05, 2014 12:08 am
Has thanked: 22 times
Been thanked: 2 times

Re: Parsing XML files in Noesis

Post by errno » Sun Jun 19, 2016 6:07 am

Thank you for your suggestions. Unfortunately I had no luck in getting them to work. Noesis keeps complaining about some missing reference in core321.zip like pyexpat. I'm thinking this might be because these missing Python libraries aren't included with the default Noesis distribution?

Reading the beginning of __NPReadMe.txt makes me think this is exactly what is happening:
A trimmed down core 3.2.1 Python implementation is included. No modules (ctypes, sockets, etc.) are included - if you want support for them, you have to create a folder called "DLLs" under the Noesis folder and put them in it. DLLs not compiled for Python 3.2.1 may or may not work.
So I guess I will have to look around the web to download the missing modules. It's a shame if it must be done this way because this means that, unless I write my own XML parser in my script and reinvent the wheel, my script will need to include these extra DLLs to work. I'm hoping I'm wrong, is there really no built-in XML parser for Noesis?

Post Reply