Is it possible to disable objects that allow ElementTree XML parser?

With lxml, I can:

from lxml import etree parser = etree.XMLParser(resolve_entities=False) 

Can I do the same with xml.etree.ElementTree xmlml file?

+4
source share
1 answer

A quick look at the source code does not show anything easier than resolve_entities=False .

Here is an excerpt from the xml.etree.ElementTree.XMLParser source :

 parser.DefaultHandlerExpand = self._default parser.StartElementHandler = self._start parser.EndElementHandler = self._end parser.CharacterDataHandler = self._data # optional callbacks parser.CommentHandler = self._comment parser.ProcessingInstructionHandler = self._pi 

There are no other pyexpat handlers.

Now you are interested in famous XML objects such as & or other? It seems that undefined objects go through XMLParser._default so that you can get something by extending this method.

But what are you trying to do with this? If this is just adding new objects, try updating the XMLParser.entity dict.

+2
source

Source: https://habr.com/ru/post/1445693/


All Articles