difference between fromstring() and XML()

Just joined the list. Going to have some more interesting questions shortly, as I am about to try implementing my own parser target and object tree, but I'll start with something simple to make sure my list subscription is working. What is the difference between lxml.etree.XML() and lxml.etree.fromstring()? -ofer

Ofer Nave, 26.06.2013 22:36:
Welcome!
What is the difference between lxml.etree.XML() and lxml.etree.fromstring()?
Does this help? http://lxml.de/tutorial.html#the-fromstring-function Stefan

So to be quite clear etree.XML and etree.fromstring are different names for the same thing, and regardless of your choice either will produce the same result. Sort of like 'int' and 'integer' for specifying a column type in MySQL. True? Martin Mueller Professor of English and Classics Northwestern University On 6/27/13 12:55 AM, "Stefan Behnel" <stefan_ml@behnel.de> wrote:

Hi, 2013/6/27 Martin Mueller <martinmueller@northwestern.edu>
I checked the source to be sure. There is a slight difference, if you install a custom parser with set_default_parser(). etree.fromstring() will always use this installed parser, but etree.XML() will only use it if it inherits from XMLParser, otherwise it will use its own XMLParser. (etree.HTML() has a similar behavior) Of course the above difference does not apply if you explicitly pass a parser object to the functions. -- Amaury Forgeot d'Arc

Amaury Forgeot d'Arc, 27.06.2013 13:13:
Right. That's because the XML() and HTML() function names are actually explicit about the expected input format, whereas fromstring() just passes on the input to whatever parser the user chose and can thus handle "anything". The main idea is really that XML()/HTML() can be used to "decorate" literals. Apart from that, all three do the same thing. Stefan

On 06/27/2013 07:30 AM, Stefan Behnel wrote:
FYI-I've spent many hours reading the docs and API over the last few weeks. I even tried skimming the source a few times to answer some questions, but didn't have much luck -- it's pretty complicated for someone who's new to Python and has never written Python bindings for a C library. :) -ofer

Ofer Nave, 26.06.2013 22:36:
Welcome!
What is the difference between lxml.etree.XML() and lxml.etree.fromstring()?
Does this help? http://lxml.de/tutorial.html#the-fromstring-function Stefan

So to be quite clear etree.XML and etree.fromstring are different names for the same thing, and regardless of your choice either will produce the same result. Sort of like 'int' and 'integer' for specifying a column type in MySQL. True? Martin Mueller Professor of English and Classics Northwestern University On 6/27/13 12:55 AM, "Stefan Behnel" <stefan_ml@behnel.de> wrote:

Hi, 2013/6/27 Martin Mueller <martinmueller@northwestern.edu>
I checked the source to be sure. There is a slight difference, if you install a custom parser with set_default_parser(). etree.fromstring() will always use this installed parser, but etree.XML() will only use it if it inherits from XMLParser, otherwise it will use its own XMLParser. (etree.HTML() has a similar behavior) Of course the above difference does not apply if you explicitly pass a parser object to the functions. -- Amaury Forgeot d'Arc

Amaury Forgeot d'Arc, 27.06.2013 13:13:
Right. That's because the XML() and HTML() function names are actually explicit about the expected input format, whereas fromstring() just passes on the input to whatever parser the user chose and can thus handle "anything". The main idea is really that XML()/HTML() can be used to "decorate" literals. Apart from that, all three do the same thing. Stefan

On 06/27/2013 07:30 AM, Stefan Behnel wrote:
FYI-I've spent many hours reading the docs and API over the last few weeks. I even tried skimming the source a few times to answer some questions, but didn't have much luck -- it's pretty complicated for someone who's new to Python and has never written Python bindings for a C library. :) -ofer
participants (4)
-
Amaury Forgeot d'Arc
-
Martin Mueller
-
Ofer Nave
-
Stefan Behnel