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 & amp; ; # 13; , almost URL encoding - but I am not using HTML, I am using XML.

For example, I have a simple text file created in Notepad, such as:

  This is my text   

Then I create some XML and add this text to XML in the XML:

  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)   

The problem is that the print is produced here:

    

Line breaks are fine for my purposes, but & amp; # 13; Elements are not there.

Find out what I am capable of doing is happening because I am opening the text file in binary mode "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.  

Now, I can dump the XML string into the string, then $ # 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.

Does anyone know a way to stop this encoding?

uses Windows \ 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. rewrite (r '\ r $', '', line) with open text ("mytext .fh: line: fh: textstr + = re.sub" (Repr (textstr) for as fh

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

jsp - Google line chart x-axis shrinks on transition -

java - Reaching JTextField in a DocumentListener -