[lxml-dev] ElementTree docinfo attribute
Hello, I can read at http://article.gmane.org/gmane.comp.python.lxml.devel/1106/match=docinfo "a DocInfo object that you can also instantiate on an ElementTree (or Element) by hand." But I also can read from _ElementTree help : "docinfo: Information about the document provided by parser and DTD. This value is only defined for ElementTree objects based on the root node of a parsed document (e.g. those returned by the parse functions)." In any case, the docinfo property of ElementTree seems read only. So please tell me, is it possible to fill the docinfo property of an ElementTree by hand, or is it necessary to use the etree parse method ? Thanks. -- David.
Hi, David Soulayrol wrote:
I can read at http://article.gmane.org/gmane.comp.python.lxml.devel/1106/match=docinfo
"a DocInfo object that you can also instantiate on an ElementTree (or Element) by hand."
But I also can read from _ElementTree help :
"docinfo: Information about the document provided by parser and DTD. This value is only defined for ElementTree objects based on the root node of a parsed document (e.g. those returned by the parse functions)."
I just added ", not for trees that were built manually." at the end, that should make it clearer.
In any case, the docinfo property of ElementTree seems read only. So please tell me, is it possible to fill the docinfo property of an ElementTree by hand, or is it necessary to use the etree parse method ?
What information would you like to add, and for what purpose? Stefan
Le samedi 23 août 2008 à 13:55 +0200, Stefan Behnel a écrit :
Hi,
David Soulayrol wrote:
I can read at http://article.gmane.org/gmane.comp.python.lxml.devel/1106/match=docinfo
"a DocInfo object that you can also instantiate on an ElementTree (or Element) by hand."
But I also can read from _ElementTree help :
"docinfo: Information about the document provided by parser and DTD. This value is only defined for ElementTree objects based on the root node of a parsed document (e.g. those returned by the parse functions)."
I just added ", not for trees that were built manually." at the end, that should make it clearer.
In any case, the docinfo property of ElementTree seems read only. So please tell me, is it possible to fill the docinfo property of an ElementTree by hand, or is it necessary to use the etree parse method ?
What information would you like to add, and for what purpose?
I have a method which takes a NS map, a root tag and DTD info and should return a correct document with all these info set. I was wondering if the only way to do this was to write everything inside a string and then call the parser with StringIO. -- David.
David Soulayrol wrote:
I have a method which takes a NS map, a root tag and DTD info and should return a correct document with all these info set. I was wondering if the only way to do this was to write everything inside a string and then call the parser with StringIO.
Ok, so the problem you have is how to set the DTD reference after creating the root Element. There isn't currently an API to do that, so you have to call the parser to create the right setting in the first place. I wouldn't mind making the public_id and system_url properties in ElementTree.docinfo (DocInfo class) writable. Patches appreciated. Stefan
participants (2)
-
David Soulayrol
-
Stefan Behnel