python - lxml adds urlencoding in xml? -
I will indicate that I am using Python 2.7.3 (x64) on Windows 7, in which LXGL 2.3 is. 6.
I have a little bit weird problem, I'm hoping someone can help it. I have not found a solution online, maybe I am not looking for the right thing.
Still, I have a problem where I am making the program with XML using LXML, then I am outputting it in a text file, problem LXML Carriage Returns to Text For example, I have a simple text file created in Notepad, such as: Then I create some XML and add this text to XML in the XML: The problem is that the print is produced here: Line breaks are fine for my purposes, but Find out what I am capable of doing is happening because I am opening the text file in binary mode Now, I can dump the XML string into the string, then Does anyone know a way to stop this encoding? uses Windows & amp; ; # 13; , almost URL encoding - but I am not using HTML, I am using XML.
This is my text
from the lxml import attribute to the line in the text entry = "" fh = open ("mytext.txt", "rb") : Textstr + = line root = etree.Element ("root") a = etree.SubElement (root, "some_element") a.text = textstr print etree.tostring (root)
& amp; # 13; Elements are not there.
"rb" (which I actually have to do because my App large text file is indexed). If I do not open the file in binary mode
"r" , then in the output
& amp; # 13; is not (but of course, my indexing doesn '
print etree.tostring (root, method = " Although there is no difference in output.
$ # 13; < / Code> Artifacts, however, was hoping for a more elegant solution - because I do not keep the text files in my control and I worry that the text file is un Other elements can be changed in the URL style without encoding without my knowledge.
\ r \ n to represent a line completion, unix
\ n It will remove
\ r at the end of the line, if there is one (hence the code will also work with unix text files). A
\ r , so if you have a
\ r somewhere else in line, it will be preserved.
Comments
Post a Comment