Parsing XML parameters by dynamic created variable names

  • Hello,

    I want to parse XML parameters by dynamic created variable names.

    The following snippet code is from the tour.xml:

    Code
    <map_settings viewpoint1_xy="30,180"
            viewpoint1_heading="0"
            viewpoint3_xy="110,180"
            viewpoint3_heading="0"
        />

    I want to parse these parameters (e.g., viewpoint1_xy) in the vtourskin.xml with the following code: (one level deeper than tour.xml)

    And the output of the debug console looks like this:

    Code
    INFO: 30,180 INFO: pos: -1
    INFO: map_settings.viewpoint2_xy
    INFO: pos: -1
    INFO: 110,180
    INFO: pos: -1
    INFO: map_settings.viewpoint4_xy
    INFO: pos: -1
    INFO: map_settings.viewpoint5_xy
    INFO: pos: -1

    The problem is, that indexoftxt always results in pos = -1, because it's not searching in the value of get(viewpointSetting) but in the variable name.

    e.g., indexoftxt(pos,'map_settings.viewpoint1_xy', ','); NOT indexoftxt(pos,'30,180', ',');

    Seems like the expression get(viewpointSetting) is not executed before indexoftxt?

    Why?

    Thanks!

    Einmal editiert, zuletzt von bafu (16. Januar 2013 um 18:56)

  • Code
    <map_settings name="viewpoint1_xy" value="30,180"
            viewpoint1_heading="0"
            viewpoint3_xy="110,180"
            viewpoint3_heading="0"
        />
    <map_settings name="viewpoint2_xy" value="30,180"
            viewpoint1_heading="0"
            viewpoint3_xy="110,180"
            viewpoint3_heading="0"
        />
    Code
    for(set(i,0), i LT 5, inc(i),
        trace( map_settings[get(i)].name, ', ', map_settings[get(i)].value);
    );

    P.S.

    Code
    for(set(i,0), i LT 5, inc(i),
    set( n, map_settings[get(i)].name);
    trace( map_settings[get(i)].name, ', ', map_settings[get(n)].value);
    );
  • Hi,

    to clear up why the code in the first post wasn't working, here a copy of my answering-mail to the same question you had also sent by mail:

    In this call:

    Code
    indexoftxt(pos,get(viewpointSetting), ',');


    the get() will be resolved to:

    Code
    indexoftxt(pos, map_settings.viewpoint2_xy, ',');


    That means the name of the variable itself will be searched and not the content of the variable itself.


    To search the content of the variable, it must be first read-out/copied to an other variable (because a get(get(var)) is not possible).
    e.g. this can be done by such code:

    Code
    copy(varcontent, get(viewpointsetting));


    After resolving the get(), the code will look like:

    Code
    copy(varcontent, map_settings.viewpoint2_xy);


    And with that code, the content from 'map_settings.viewpoint2_xy' will be copied to 'varcontent'.
    That new 'varcontent' variable can now by used to as get(varcontent) in the indexoftxt() call.


    That means the final working code will look like this:

    Code
    txtadd(viewpointsetting, 'map_settings.viewpoint', get(cnt), '_xy'); 
    copy(varcontent, get(viewpointsetting)); 
    indexoftxt(pos, get(varcontent), ',');


    Best regards,
    Klaus

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!