How do I create a Python Placeholder for Elements that are Empty parsed from an XML File? -


i want start off saying new python, love language.

problem: provided large juniper configuration file in xml format. using elementtree library parse through file. file has 5 main roots (parents) , several nested children. trying append text several list several element tags , display data. have verified paths each. think problem elements empty, when display data each of list, corresponding data output not match within xml document. there way tell elementtree when parsing document , appending element list, if element text empty append "none" string? element placeholder speak. hope when display data of several lists, match within xml document because same number of elements accounted in iteration each list.

thank you!

code example:

import xml.etree.elementtree et  # file parse, submit memory tree = et.parse('juniperxmlconf-name-newsslvpna.xml') root = tree.getroot()  #defining relevant root tag.  children of root tag  user_realms = root[3][0] user_roles = root[3][1]   #defining dictionaries children of children (subelements)  name = [] idletimeout = [] maxtimeout = [] reminder = [] limit_concurrent_users = [] guaranteed_minimum = [] maximum = [] max_sessions_per_user = [] user_names = []  # parsing data lists user_roles.  #notice .text method  child in user_roles:     try:         name.append(child[0].text)     except indexerror:         continue ... ...  # counter displays data name argument  = 0 value in (name):     try:         += 1         print("name: {}, idletimeout {}, maxtimeout {}, reminder {}".format(name[i],              idletimeout[i], maxtimeout[i], reminder[i]))     except indexerror:         break   """ example of xml: """  <users>         <user-realms>             <realm>                 <name>customer name here</name>                 <authentication-policy>                     <source-ip>                         <customized>any-ip</customized>                         <ips>                         </ips>                     </source-ip>                     <browser>                         <customized>user-agent here</customized>                         <user-agent-patterns>                         </user-agent-patterns>                     </browser>     ........     ........     <users>             <user-realms>                 <realm>                     <name></name>                     <authentication-policy>                         <source-ip>                             <customized>any-ip</customized>                             <ips>                             </ips>                         </source-ip>                         <browser>                             <customized>user-agent here</customized>                             <user-agent-patterns>                             </user-agent-patterns>                         </browser> 


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -