Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Looping with etree
    primarykey
    data
    text
    <p>I'm sure many of you have seen the inundation of minidom questions I've had as of late. This weekend, I finally gave up and moved to etree, and have one simple question: How should I be looping this to give the output in the following format:</p> <p>Name Class_Name members color #field y #field z</p> <p>XML example (there are many different types of Class_Name):</p> <pre><code>&lt;network_objects&gt; &lt;network_object&gt; &lt;Name&gt;Test_Group_A&lt;/Name&gt; &lt;Class_Name&gt;network_object_group&lt;/Class_Name&gt; &lt;members&gt; &lt;reference&gt; &lt;Name&gt;Host1&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host2&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host3&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host4&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host5&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host6&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;reference&gt; &lt;Name&gt;Host7&lt;/Name&gt; &lt;Table&gt;network_objects&lt;/Table&gt; &lt;/reference&gt; &lt;/members&gt; &lt;color&gt;&lt;![CDATA[deep pink]]&gt;&lt;/color&gt; &lt;comments&gt;&lt;![CDATA[no comment]]&gt;&lt;/comments&gt; &lt;group_convention_query&gt;&lt;![CDATA[]]&gt;&lt;/group_convention_query&gt; &lt;group_sort_type&gt;3&lt;/group_sort_type&gt; &lt;is_convention_on&gt;false&lt;/is_convention_on&gt; &lt;member_class&gt;&lt;![CDATA[network_object]]&gt;&lt;/member_class&gt; &lt;members_query&gt;&lt;![CDATA[]]&gt;&lt;/members_query&gt; &lt;type&gt;&lt;![CDATA[group]]&gt;&lt;/type&gt; &lt;/network_object&gt; &lt;/network_objects&gt; </code></pre> <p>The following code gives me one iteration of each name (what I want):</p> <pre><code>for Name in tree.iterfind('network_object/Name'): print (Name.text) </code></pre> <p>However, if I do a for loop within the for loop, I get an output of all names, with all variations of Class_Name (versus what it is in reality). For instance:</p> <pre><code>for Name in tree.iterfind('network_object/Name'): for Class_name in tree.iterfind('network_object/Class_Name'): print (Name.text,Class_name.text) DB_Servers host_plain DB_Servers network_object_group DB_Servers dynamic_object </code></pre> <p>etc etc, I'm sure you get the idea. </p> <p>How would I go about collecting all of the data I need, and then placing each object with it's relevant details, on it's own line?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload