Convert a long XML string into indented format

Laguna ed_zeng at yahoo.com
Wed Jan 25 13:58:45 EST 2006


Hi,

I have an XML file in a single long string. How can I convert it into
the nicely indented format as displayed by Internet Explorer using
Python?

Thanks,
Laguna

Input XML file (one continuous string without newline):

<!-- $Revision: 12 $ --> <!-- $Date: 12/13/04 5:13p $ --> <control>
<schedule> <minute>*/2</minute> <hour>*</hour>
<day_of_month>*</day_of_month> <month>*</month>
<day_of_week>*</day_of_week> </schedule> </control>

Output XML file:

  <!--  $Revision: 12 $   -->
  <!--  $Date: 12/13/04 5:13p $   -->
  <control>
	<schedule>
		<minute>*/2</minute>
		<hour>*</hour>
		<day_of_month>*</day_of_month>
		<month>*</month>
		<day_of_week>*</day_of_week> 
	</schedule>
  </control>




More information about the Python-list mailing list