Path://var_null/
 Регистрация или ->Экспорт данныхПоиск
Войти
Экспорт:
Папки

/root/polzovateli/var_null/yaziki-programmirovaniya/python/XML-modifikaciya/lxml
Не экспортировать закрытые директории
Преобразовывать заметки в html
Экспортировать
Удалить директорию
Применить
 Стили директорииДобавить заметку
Удаление Элемента
2014-12-11 15:55:08 Удалить Фон Изображение Импорт из текстового файла Редактировать Копировать в буфер
el_xml.remove(child_xml)
Похожие разделы:
->var_null:root/Пользователи/var_null/Языки программирования/python/XML Модификация/lxml/ (текущий раздел)
Модификация xml из файла
2014-12-03 16:21:25 Удалить Фон Изображение Импорт из текстового файла Редактировать Копировать в буфер
	path_header = data['source'] + "/" + data['etalon_dir_parser'] + "/_header.xml"; 
	path_header_tmp = data['source'] + "/" + data['etalon_dir_parser'] + "/_header_tmp.xml"; 
	
	tree = etree.parse(path_header)	
	
	root = tree.getroot()
	
	for child in root:
	
		#print child.tag, child.attrib	
		
		if(child.tag == "acc_obj"):
		
			acc_obj = child
		
			add = etree.Element("created_by")
			
			add.attrib['n']='1'
				
			acc_obj.append(add)
			
				
	xml_string = etree.tostring(tree, encoding="utf-8", method="xml")		
	
	my_file = open(path_header_tmp, 'w')
	my_file.write(xml_string)	
				
Модификация xml из строки
2014-12-03 15:34:27 Удалить Фон Изображение Импорт из текстового файла Редактировать Копировать в буфер
from lxml import etree

file_header_tmp = open(path_header_tmp, 'a')

content_tpl = ""
file = open(path_header) #открываем файл
for line in file.readlines():
	content_tpl += line 	
	
print(content_tpl)	
		
root = etree.fromstring(content_tpl)	
	
for child in root:
	
	print child.tag, child.attrib

	if(child.tag == "my_el"):
		
		add = etree.Element("add_el")
				
		child.append(add)


xml_string = etree.tostring(root, encoding="utf-8", method="xml")		
	
my_file = open(path_header_tmp, 'w')
my_file.write(xml_string)	
Участвуй в наполнении сайта, создай свое дерево знаний. Регистрация

@include_encode 2015