Load entity definitions from DTD
Hello, I have a quite basic issue with loading entity definitions from a DTD that I can’t wrap my head around: I have an XML file that declares its DTD: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE StupidXML SYSTEM "bwl.dtd" []> <StupidXML> <bwlengl wcn="1" elabel="vulture; bird (gen.)"></bwlengl> ... In that DTD, a couple of entities are declared. It is in the same directory as the XML file. Now I try to parse the XML file: etree.parse('BWL.xml', parser=etree.XMLParser(load_dtd=True)) Now this works if my current working directory is the one where the XML file and DTD are located. This fails with an XMLSyntaxError (Entity not defined) when my current working directory is somewhere else. Now I thought that the path to the DTD should be interpreted as being relative to the location of the XML file, not relative to Python’s working directory. Am I wrong? How would I preferably solve this? Thanks, Frederik
Elwert, 21.05.2014 15:18:
I have a quite basic issue with loading entity definitions from a DTD that I can’t wrap my head around:
I have an XML file that declares its DTD:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE StupidXML SYSTEM "bwl.dtd" []> <StupidXML> <bwlengl wcn="1" elabel="vulture; bird (gen.)"></bwlengl> ...
In that DTD, a couple of entities are declared. It is in the same directory as the XML file.
Now I try to parse the XML file:
etree.parse('BWL.xml', parser=etree.XMLParser(load_dtd=True))
Now this works if my current working directory is the one where the XML file and DTD are located. This fails with an XMLSyntaxError (Entity not defined) when my current working directory is somewhere else.
Now I thought that the path to the DTD should be interpreted as being relative to the location of the XML file, not relative to Python’s working directory. Am I wrong? How would I preferably solve this?
Did you try passing the absolute path to the XML file into parse()? Stefan
participants (2)
-
Frederik Elwert -
Stefan Behnel