lxml question
Stefan Behnel
stefan_ml at behnel.de
Fri Oct 3 12:22:05 EDT 2008
More information about the Python-list mailing list
Fri Oct 3 12:22:05 EDT 2008
- Previous message (by thread): lxml and adding a stylesheet
- Next message (by thread): SimpleXMLRPCServer -- turning off request log?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Uwe Schmitt wrote:
> I have to parse some text which pretends to be XML. lxml does not want
> to parse it, because it lacks a root element.
> I think that this situation is not unusual, so: is there a way to
> force lxml to parse it ?
>
> My work around is wrapping the text with "<root>...</root>" before
> feeding lxmls parser.
Yes, you can do that. To avoid creating an intermediate string, you can use
the feed parser and do something like this:
parser = etree.XMLParser()
parser.feed("<root>")
parser.feed(your_xml_tag_sequence_data)
parser.feed("</root>")
root = parser.close()
Stefan
- Previous message (by thread): lxml and adding a stylesheet
- Next message (by thread): SimpleXMLRPCServer -- turning off request log?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list