0

I've been helping some students with a Python class this fall, and I've noticed that several students using Mac OS to complete a particular assignment involving validating XML against XSD's are running into OS Errors ("Error reading file: failed to load eternal entity [the xml file]"). Their code works perfectly fine on my end (Windows) but on Mac OS it refuses to.

Here is the code that is causing the problem:

from lxml import etree

xmlschema_doc = etree.parse("the_xsd.xsd")
xmlschema = etree.XMLSchema(xmlschema_doc)
doc = etree.parse("the_xml.xml")
print(xmlschema.validate(doc))

In particular, the line doc = etree.parse("the_xml.xml") is where the error occurs.

I've made sure the students 1) have all their files (XML, Python, XSD) in the same folder, 2) I've suggested they use the full filepaths and 3) I found this bit of code and suggested they try it (to no avail):

prog_dir = os.path.abspath(os.path.dirname(__file__))
os.chdir(prog_dir)

Again: the XML validates against the XSD on Windows just fine, but on their Macs they get the error.

Any insights would be much appreciated.

Sarah Diri
  • 97
  • 1
  • 9
  • 1
    what is the line ending of the files – rioV8 Dec 01 '20 at 04:33
  • indeed, it might be related to the line ending (linux vs windows vs mac) https://stackoverflow.com/questions/6373888/converting-newline-formatting-from-mac-to-windows – blurfus Dec 01 '20 at 05:03
  • To clarify: the line ending of all the files, or just the xml in particular? And, in that case, how could it be accounted for when coding on Mac OS? – Sarah Diri Dec 01 '20 at 05:14
  • Checking the XML file it seems the line ending is /r/n @rioV8 – Sarah Diri Dec 01 '20 at 05:25
  • 1
    do you also get an error if you parse the XML without XSD – rioV8 Dec 01 '20 at 10:16
  • 1
    Could also be related to file path separators in xs:import or xs:include statements in the XSD. – kimbert Dec 01 '20 at 14:12
  • @riov8 I had the student attempt to run a Python file that just parsed the XML without the XSD and she said she could not run that, either. – Sarah Diri Dec 02 '20 at 05:00
  • then simplify the XML, remove tags, until you can parse the XML and find out which tag is the trouble – rioV8 Dec 02 '20 at 12:01

0 Answers0