includexml -- getting it to work

  • Includexml seems like just what I was looking for, to let me load in new arrays and data in an xml file when I switch from one tour to another.

    Yet when I do it, I don't seem to see the values. With an xml file with contents like:


    If I do insertxml of this file, and attempt to print out values like ti[0].name or tii.tname or testval.val they are all empty (it prints the variable name not a value.)

    I am of course in HTML5 mode with the latest 20.9

    Previously I was trying to do it with loadpano and MERGE but that seems to delete the <image> tag, otherwise it would work. (It also re-runs various events but I could have gotten around that.)

    The only other way I have found to do it is to have every image's XML file include the array with a filename with $tourname in it, but that include has to be done when loading the XML. So I have set the $tourname in the calling HTML and that works to define the first tour array, but does not let you switch tours as far as I can tell.

    Any hints on where to look to make this work?

  • Perhaps I misread the documents. So I need to invoke more code in a callback function, I can't just include the XML and then continue on in the ordinary control flow? I was imagining it more like a typical routine one calls to load in some data, and moves on from there. I will see if I can rewrite this based on callback, though that presents a problem for the functions wanting to call my array loading function as their control flow has to become event driven rather than procedural.

    As a commentary though, I find it considerably less useful in this form. The documentation suggested the callback function was optional, it sounds like it's not really optional unless you don't wish to do anything with the information you loaded.

    If I read you right, then it's more meant to be used to just make dynamic decisions of what XML to load in when you are loading in an image, not for saying, "the user has clicked a hotspot saying he wants to move to the next pano, let's load data to see where that is and then go to it." I think I can work around that.

    Mostly this was being used to get around the fact that <include> tags can't use variables in them except the variables which come from HTML, not even variables set by loadpano() if I read the documentation right where it says that variables passed to loadpano are only available after XML is parsed.

    However, I presume with includexml, I can effectively treat it like a more dynamic include then -- once the xml is parsed and the pano is loaded, I can then include more XML based on variables passed in loadpano or via HTML so the data are ready if a user clicks on a hotspot, for example.

  • Hi,

    loading a file from a server always takes some time. Blocking everything until the included file would be loaded would be a bad experience and slow. The viewer can load and decode images in the meantime or process other things.

    Simple put code that depends on the included xml into the loaddone callback, e.g.

    Code
    includexml('otherxml.xml',
       code_that_depends_on_the_included_xml();
       ...
    );
    code_that_does_NOT_depends_on_the_included_xml();
    ...

    If you want to include multiple xml files (and load them in parallel) and wait until all are loaded you could do something like this:

    Code
    set(xml_files_loaded, 0);
    includexml('1.xml', inc(xml_files_loaded));
    includexml('2.xml', inc(xml_files_loaded));
    includexml('3.xml', inc(xml_files_loaded));
    callwhen(xml_files_loaded == 3,
       trace(all 3 xml files are loaded now);
       ...
    );

    Best regards,
    Klaus

  • Yes, thanks -- I just had not realized it was asynchronous, though I understand why it is. For me, since what I will do with the data can't be done until it is loaded, a blocking call would have been useful, but I understand the issue with doing that in general. Since this code is likely to be called inside its own thread anyway (ie. a user has clicked on a hotspot or we are in the process of loading a pano) one could generally use a blocking version. But I will rewrite the code to work with a non-blocking version.

    Another option that would have solved my problem, by the way, would be if variables passed to loadpano could be used in <include> directives, the same way that variables that are passed from the HTML/javascript can be used in those directives. Or existing variables with "keep" on. It seemed there was no reason not to allow those variables to be used, as they are ready before the xml is parsed, so I was not clear on why loadpano's variables are limited in that way.

    However, includexml is a more general solution that I think many can find useful if they want to be able to load data and other XML based on something the user does in a pano, so I like it broadly.

  • Hi,

    for overwriting variables, just 'set' them after loading (in the loaddone callback).

    The 'vars' settings in the loadpano call is doing the same (that vars is mainly there for backward compatibility, technically is simply setting the variable after loading).

    That means:

    Code
    loadpano(test.xml, var1=abc, var2=xyz);

    is the same as:

    Code
    loadpano(test.xml);
    set(var1,abc);
    set(var2,xyz);

    and for includexml it would look like this:

    Code
    includexml(test.xml, 
      set(var1,abc);
      set(var2,xyz);
    );

    Best regards,
    Klaus

Participate now!

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