0

I have a string with xml:

string = '<catalog><category>iPhone</category><category>iPad</category><category>iPod</category><category>iMac</category><category>MacBook</category><category>Mac Mini</category><category>Чехлы</category><category>Защитные пленки</category><category>Акксессуары</category><category>Наушники и гарнитуры</category><category>Переходники и Провода</category><category>Автомобильные аксессуары</category><category>Aккустические системы</category><category>Зарядные устройства</category><category>Видео очки</category><category>Wi-Fi оборудование</category><category>Аккумуляторы и блоки питания</category><category>BlackBerry</category><category>Подставки и док-станции</category><category>Игрушки</category><category>Цифровые ручки</category><category>Полезные устройства</category><category>Планшетные компьютеры</category><category>Samsung</category><category>GoPro</category><category>Память</category></catalog>' 

please tell me how to display this xml on the screen indented reflecting nesting.

0

2 Answers 2

1

use pretty_print=True:

In [95]: from lxml import etree In [97]: rt=etree.fromstring(string) In [98]: print etree.tostring(rt, pretty_print=True) 
Sign up to request clarification or add additional context in comments.

Comments

0

You have to use xml module

import xml.dom.minidom xml_obj = xml.dom.minidom.parseString(string) xml_indent_string = xml.toprettyxml() print xml_indent_string 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.