python 2.7 - Creating xml file with python2.7 -


i trying write out xml file based on file names extract upstream process. upstream process me name of files/strings say: apple, bananas, cow .. , trying add them inside members tag, iterating on list.

and trying generate xml this:

<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://soap.xyz.com/2006/04/metadata">     <types>         <members>apple</members>         <members>bananas</members>         <members>cow</members>         <name>flow</name>     </types>     <version>38.0</version> </package> 

so far, having difficulty in iterating list append members , not override it. also, not sure if should append keeping xml template no members in it. or write out xml's every process. inserting xmlns seems issue while creating xml. below have been trying out.

import os if os.path.isdir("c:\\users\\nokram\\documents\\temp\\g_e\\src\\flows"):     relevant_path = "c:\\users\\nokram\\documents\\temp\\g_e\\src\\flows"     included_extenstions = ['flow']     file_names = [os.path.splitext(fn)[0] fn in os.listdir(relevant_path)               if any(fn.endswith(ext) ext in included_extenstions)]     #print (file_names)     #print (type(file_names))     ##create xml here list     xml.etree.elementtree import element, subelement, tostring      root = element("package")     #root.register_namespace('',"http://soap.xyz.com/2006/04/metadata")     child = subelement(root, "types")     child1 = subelement(child, "members")     child2 = subelement(child, "name")     #add iteration here child tag     f in file_names:         child1.text=str(f)     child2.text="flow"     print tostring(root) else:     print ("flows doesn't exist") 


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -