svdhoog / FLAViz

FLAViz: Flexible Large-scale Agent Visualization Library
GNU General Public License v3.0
1 stars 4 forks source link

Problem with parsing model XML files that have 2 levels of nested models #2

Open svdhoog opened 6 years ago

svdhoog commented 6 years ago

File: src/data_conversion_scripts/src/xml_hdf5

Problem:

When converting directly from XML to H5, the Python script needs the model.xml path and model.xml file. If the model contains 2 nested models, then parsing the root model.xml file does not work correctly.

Reason: Apparently, the XML parser expects relative paths inside the model.xml while xparser uses absolute paths, relative to the root path of the model.

Solution: (Workaround/hack): whenever a nested model.xml file is about to be parsed, re-set the root to the root model folder where we started (the top model folder).

Examples:

Example 1 Structure that works with xparser 0.17.1, but not with standard XML parser that expects relative paths:

-main_model.xml:

<xmodel version="2">
 <name>ABM_Model</name>
 <version>1.0</version>
 <description></description>
 <models>
  <model>
   <file>Subfolder/Level1_nested_model.xml</file>
   <enabled>true</enabled>
  </model>
<environment>
 ...
<xmodel version="2">
 <name>ABM_Model</name>
 <version>1.0</version>
 <description></description>
 <models>
  <model>
   <file>Subfolder/subsubfolder/Level2_nested_model.xml</file>
   <enabled>true</enabled>
  </model>
<environment>
 ...

Example 2 Structure that does not work with xparser 0.17.1, but that is most likely expected by a default XML parser in Python (using the relative path, once traversed into the Level1 subfolder):

-main_model.xml:

<xmodel version="2">
 <name>ABM_Model</name>
 <version>1.0</version>
 <description></description>
 <models>
  <model>
   <file>Subfolder/Level1_nested_model.xml</file>
   <enabled>true</enabled>
  </model>
<environment>
 ...
<xmodel version="2">
 <name>ABM_Model</name>
 <version>1.0</version>
 <description></description>
 <models>
  <model>
   <file>subsubfolder/Level2_nested_model.xml</file>
   <enabled>true</enabled>
  </model>
<environment>
 ...

Reason this works: when the XML parser parses the root model.xml, it parses the line <file>Subfolder/Level1_nested_model.xml</file>, transcends into that subfolder, and starts to parse the file Level1_nested_model.xml. This refers to <file>subsubfolder/Level2_nested_model.xml</file> which exists relative to Subfolder.

0xfabi commented 6 years ago

Hi Sander, can you tell me how exactly I can reproduce the error? How do you execute it from cmd and which files do you use exactly? (the following arguments are required: modelpath, model_file_name, datapath)