Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing an arbitrary XML file with ElementTree
    primarykey
    data
    text
    <p>I have a template XML file, and based on inputs given to my program I have to generate a new XML file. The template has sections that need to be repeated based on the input data. But I don't necessarily know the structure of these sections or how many levels of nesting they have. I cannot figure out how to read in the template file in an arbitrary way they will let me populate it and then output it. Here is a section of the template file:</p> <pre><code>&lt;Target_Table&gt; &lt;Target_Name&gt;SF1_T1&lt;/Target_Name&gt; &lt;Target_Mode&gt; &lt;REP&gt; &lt;Target_Location_To_Repeat&gt; &lt;XLocation&gt;nextXREL&lt;/XLocation&gt; &lt;YLocation&gt;nextYREL&lt;/YLocation&gt; &lt;/Target_Location_To_Repeat&gt; &lt;Target_Location_To_Repeat&gt; &lt;XLocation&gt;nextXREL&lt;/XLocation&gt; &lt;YLocation&gt;nextYREL&lt;/YLocation&gt; &lt;/Target_Location_To_Repeat&gt; &lt;/REP&gt; &lt;/Target_Mode&gt; &lt;Target_Repetitions&gt;1&lt;/Target_Repetitions&gt; &lt;Meas_Window&gt; &lt;Window_Size&gt; &lt;XLocation&gt;FOV&lt;/XLocation&gt; &lt;YLocation&gt;FOV&lt;/YLocation&gt; &lt;/Window_Size&gt; &lt;Window_Location&gt; &lt;XLocation&gt;firstXREL&lt;/XLocation&gt; &lt;YLocation&gt;firstYREL&lt;/YLocation&gt; &lt;/Window_Location&gt; &lt;/Meas_Window&gt; &lt;Box_Orientation&gt;90&lt;/Box_Orientation&gt; &lt;First_Feature Value="Space" /&gt; &lt;Meas_Params_Definition&gt; &lt;Number_Of_Lines Value="Auto" /&gt; &lt;Number_Of_Pixels_Per_Line Value="Auto" /&gt; &lt;Averaging_Factor Value="1" /&gt; &lt;/Meas_Params_Definition&gt; &lt;Number_Of_Edges&gt;1&lt;/Number_Of_Edges&gt; &lt;Edge_Pair&gt; &lt;Edge_Pair_Couple&gt; &lt;First_Edge&gt;1&lt;/First_Edge&gt; &lt;Second_Edge&gt;1&lt;/Second_Edge&gt; &lt;/Edge_Pair_Couple&gt; &lt;Nominal_Corrected_Value&gt;0&lt;/Nominal_Corrected_Value&gt; &lt;/Edge_Pair&gt; &lt;Categories&gt; &lt;Material_Type /&gt; &lt;Meas_Type /&gt; &lt;Category_Type /&gt; &lt;Other_Type /&gt; &lt;/Categories&gt; &lt;Bias&gt;0&lt;/Bias&gt; &lt;Template_Target_Name&gt;SF_IMAQ_Template_Target&lt;/Template_Target_Name&gt; &lt;Template_Target_PPL&gt; &lt;Process&gt;PC2&lt;/Process&gt; &lt;Product&gt;PD2&lt;/Product&gt; &lt;Layer&gt;L2&lt;/Layer&gt; &lt;/Template_Target_PPL&gt; &lt;Meas_Auto_Box&gt; &lt;Error_Code&gt;0&lt;/Error_Code&gt; &lt;Measured_CD&gt;0&lt;/Measured_CD&gt; &lt;Constant_NM2Pix&gt;true&lt;/Constant_NM2Pix&gt; &lt;/Meas_Auto_Box&gt; &lt;Meas_Box_Pix_Size_X&gt;PixelSize&lt;/Meas_Box_Pix_Size_X&gt; &lt;Macro_CD&gt;0&lt;/Macro_CD&gt; &lt;/Target_Table&gt; </code></pre> <p>I need to repeat the entire Target_Table section multiple time, and within each Target_Table I need to repeat the REP section multiple times. I want to write my program so that if the template changes (e.g, more levels of nesting are added) I don't have to change my program. But it seems to me that I have to totally know the structure of the file to read it in and spit it out. Is that true or am I missing something here? Is there a way to write a program that will read in a file with an unknown tags and unknown levels of nesting? </p>
    singulars
    1. This table or related slice is empty.
    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.
    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