Issue1537
Created on 2010-01-11.20:37:25 by kwatford, last changed 2010-04-18.17:16:23 by amak.
| Messages | |||
|---|---|---|---|
| msg5423 (view) | Author: Ken Watford (kwatford) | Date: 2010-01-11.20:37:24 | |
I'm using jython2.5.1 in MATLAB's JVM. Upon trying to parse an XML file with ElementTree, XMLParser.__init__ tries to get XMLReaderFactory to find "org.python.apache.xerces.parsers.SAXParser". Probably due to limitations in MATLAB's stupid classloader, this does not work (throws a SAXException/ClassNotFoundException) The only relevant comment on why this weird name is used is expat.py line 51: "Name mangled by jarjar?". Manually setting expat._xerces_parser to "org.apache.xerces.parsers.SAXParser" resolves the issue. Perhaps a try block around the XMLReaderFactory call? |
|||
| msg5720 (view) | Author: Alan Kennedy (amak) | Date: 2010-04-16.16:52:16 | |
Hmm, that's odd. If the classorg.python.apache.xerces.parsers.SAXParser is not found, then it should throw an ImportError. Please can you try these statements on a jython command line and report the results? >>> import org.python.apache.xerces.parsers.SAXParser >>> import org.apache.xerces.parsers.SAXParser Thanks. |
|||
| msg5721 (view) | Author: Ken Watford (kwatford) | Date: 2010-04-16.17:24:55 | |
Due to the way MATLAB manhandles its filehandles I can't use a real Jython prompt, but I can push to an InteractiveConsole just fine. Here are the results, plus the results with my workaround:
>> ic = org.python.util.InteractiveConsole();
>> ic.push('import org.python.apache.xerces.parsers.SAXParser');
>> ic.push('import org.apache.xerces.parsers.SAXParser');
>> ic.push('import xml.etree.ElementTree as etree');
>> ic.push('x = etree.parse("test.xml")');
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/amd/ss01/export/homes16/kwatford/TUF/jlib/jython-2.5.1.jar/Lib/xml/etree/ElementTree.py", line 862, in parse
File "/amd/ss01/export/homes16/kwatford/TUF/jlib/jython-2.5.1.jar/Lib/xml/etree/ElementTree.py", line 581, in parse
File "/amd/ss01/export/homes16/kwatford/TUF/jlib/jython-2.5.1.jar/Lib/xml/etree/ElementTree.py", line 1120, in __init__
File "/amd/ss01/export/homes16/kwatford/TUF/jlib/jython-2.5.1.jar/Lib/xml/parsers/expat.py", line 63, in ParserCreate
File "/amd/ss01/export/homes16/kwatford/TUF/jlib/jython-2.5.1.jar/Lib/xml/parsers/expat.py", line 91, in __init__
at org.xml.sax.helpers.XMLReaderFactory.loadClass(Unknown Source)
at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
org.xml.sax.SAXException: java.lang.ClassNotFoundException: org.python.apache.xerces.parsers.SAXParser
>> ic.push('import xml.parsers.expat');
>> ic.push('xml.parsers.expat._xerces_parser = "org.apache.xerces.parsers.SAXParser"');
>> ic.push('x = etree.parse("test.xml")');
>> ic.push('print x');
<xml.etree.ElementTree.ElementTree instance at 0x2>
|
|||
| msg5723 (view) | Author: Alan Kennedy (amak) | Date: 2010-04-16.17:55:11 | |
Please can you do just this bit?
>> ic.push('import org.python.apache.xerces.parsers.SAXParser');
I want to see what it generates. It should generate an ImportError.
|
|||
| msg5724 (view) | Author: Ken Watford (kwatford) | Date: 2010-04-16.18:01:27 | |
As you can see, that's the first thing I did, and no exception was thrown. I just tried it again in a fresh session, and still no exception. They both import just fine. |
|||
| msg5735 (view) | Author: Alan Kennedy (amak) | Date: 2010-04-18.17:09:23 | |
I'm not sure what to do about this problem. If >>> import org.python.apache.xerces.parsers.SAXParser succeeds, then the class should be loadable. But an attempt to instantiate the class later fails with a java.lang.ClassNotFoundException: org.python.apache.xerces.parsers.SAXParser I can only recommend that you make use of the fix you have already identified, i.e. explicitly set the value of _xerces_parser. I don't see what benefit a try block around the XMLReaderFactory would bring? |
|||
| msg5736 (view) | Author: Alan Kennedy (amak) | Date: 2010-04-18.17:16:22 | |
I'm not sure what to do about this problem. If >>> import org.python.apache.xerces.parsers.SAXParser succeeds, then the class should be loadable. But an attempt to instantiate the class later fails with a java.lang.ClassNotFoundException: org.python.apache.xerces.parsers.SAXParser I can only recommend that you make use of the fix you have already identified, i.e. explicitly set the value of _xerces_parser. I don't see what benefit a try block around the XMLReaderFactory would bring? |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2010-04-18 17:16:23 | amak | set | messages: + msg5736 |
| 2010-04-18 17:12:38 | amak | set | messages: + msg5735 |
| 2010-04-16 18:01:27 | kwatford | set | messages: + msg5724 |
| 2010-04-16 17:55:12 | amak | set | messages: + msg5723 |
| 2010-04-16 17:24:56 | kwatford | set | messages: + msg5721 |
| 2010-04-16 16:52:16 | amak | set | nosy:
+ amak messages: + msg5720 |
| 2010-01-11 20:37:25 | kwatford | create | |