1

I use the python, lxml package. I am wondering if someone knows how to output an element with fixed specified locations for the attributes.

MMain = etree.Element('DockingConfig', FormatVersion="8", InsideFill="True", InnerMinimum="20, 20", SavedAt="1/27/2014 2:01:47 PM")
outfile.write(etree.tostring(MMain, pretty_print=True))

if I output this, it will sort out the attributes alphabetically, which is not what i want as an output.

My second question is that, how can I generate my output file with encoding of "Encode in UCS-2 Little edition". This makes it to be "utf-16"

print(etree.tostring(MMain, pretty_print=True, encoding="utf-16"))

Thanks

Hamid K
  • 983
  • 1
  • 18
  • 40

1 Answers1

1

As for your first question, this seems to be a good answer.

As for your second question, the "tostring()" method follows this standard (as per the documentation).

Community
  • 1
  • 1
poli_g
  • 629
  • 3
  • 15
  • Sorry for my late replay, I did not have enough point to do an action. The first answer works well (thanks). I tried all different solutions for the second question. But still I am not able to make the file in Unicode format. The way I resolved the issue was using the "Type" command in windows added to my Python program to convert ANSI file format to Unicode. – Hamid K Mar 02 '15 at 17:55