Separate layer structure from layer properties

  • Hi!

    I feel a bit stuck with a quite simple trick which does not work...

    I've got this piece of code in one file:

    Code
    <!-- STRUCTURE -->
    <layer name="layer1">
    	<layer name="layer2"/>
    </layer>
    
    
    <!-- PROPERTIES -->
    <layer name="layer1" keep="true" --- and all layer properties go here --- />
    <layer name="layer2" keep="true" --- and all layer properties go here ---/>

    It does not work!
    Layer 2 does not recognize layer1 as parent

    I don't want to specify parent in "properties" part like this:

    Code
    <!-- STRUCTURE -->
    <layer name="layer1">
    	<layer name="layer2"/>
    </layer>
    
    
    <!-- PROPERTIES -->
    <layer name="layer1" keep="true" --- and all layer properties go here --- />
    <layer name="layer2" keep="true" parent="layer1" --- and all layer properties go here ---/>

    because "structure" part won't make sense this way. And I'd like to have structure part as a description of parent-child relationship between two layers.

    I remember about property overriding but it seems not to work here.
    What am I doing wrong?

  • It seems to me that you need to write this way?

    Code
    <!-- STRUCTURE -->
    <layer name="layer1" style="layer1" >
    	<layer name="layer2" style="layer2" />
    </layer>
    
    
    <!-- PROPERTIES -->
    <style name="layer1" keep="true" --- and all layer properties go here --- />
    <style name="layer2" keep="true" --- and all layer properties go here ---/>

    Viable idea, it will work
    Now we need to figure out why overriding doesn't :)

  • san7 already gave the answer

    you cant define two elements with name="layer1" in the same xml, anyway. that should trigger an xml error.
    that works only using two xml files, and then the second one overwrites the definition of the first one.

    there won't be an XML error if you define two layers with same names in one file.

    I've checked my code in different projects where layer data is split to different files and it seems that parent-child relationship can not be overridden, only overwritten. In each case I had to specify "parent" property to make things work correct.

    Shame shame, I wished parent property to be overrideable too...

  • Hi,

    redefining xml elements to add or overwrite settings from them is possible,
    but the xml tree-structure itself would need to be redefined too.

    That 'flattening' of the xml structure to the named layers elements happens later after the xml parsing.

    That means when you have a structure like this:

    Code
    <layer name="layer1" style="layer1" >
    	<layer name="layer2" style="layer2" />
    </layer>

    and want to add properites later, then the same xml structure need to be defined again:

    Code
    <layer name="layer1" properties="here" ...>
    	<layer name="layer2" properties="here" ... />
    </layer>

    See the 'vtourskin_design_ultra_light.xml' (in the 'tempaltes/xml/skin/' folder) as example - there this is done too.

    Alternatively could use use actions to define the properties, then the xml structure doesn't matter anymore, e.g. this way:

    Code
    <action autorun="preinit">
      set(layer[layer1], setting1=value1, setting2=value2, setting3=value3);
      set(layer[layer2], setting1=value1, setting2=value2, setting3=value3);
      ...
    </action>



    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!