
Peng Yu schrieb am 20.12.2017 um 20:30:
On Wed, Dec 20, 2017 at 11:33 AM Stefan Behnel wrote:
Am 20. Dezember 2017 15:20:35 MEZ schrieb Peng Yu: >I am trying to find out the difference between XML() and fromstring() >in etree. But it seems that they are the same. Does anybody know if >what is the main difference between them? http://lxml.de/tutorial.html#the-fromstring-function
I still don't see any practical difference other than the function names different.
Quoting from the above link: """" The XML() function behaves like the fromstring() function, but is commonly used to write XML literals right into the source """ Meaning, the difference is in use cases and their readability, not in functionality. If you have an XML literal in your code, it looks good to write XML("<root />") If you received a string from somewhere that contains XML, it looks better to write fromstring(data) Stefan