[SOLVED]How to get property of external .xml

  • Hi, please I need an example or tips for this:

    How to get a property of a scene from an external .xml? For example, in other.xml there is a scene called otherscene with the property otherprop="anyprop" . So what would the code be like: trace(get(...

    Thanks in advance,

    Fdo

  • if your other xml is included there is no "other" then its contents are part of the main xml / data as everything else.

    --> trace(*scene{otherscene].otherprop);

    if your other xml is not included things get difficult...

    if you structure it as <krpano> </krpano> xml you can load it using loadxml() or includexml()

    but note that its data will get merged with your main xml in this case

    ...

    question is what is this other xml and what are these other scenes ? :)

    ...

    " trace(get(... " <-- fyi get() is not needed in trace()

  • Hi, thanks for the help. The idea is to access the value of a property that is in an external .xml that I use with popup(iframe... That is, I have a hotspot that opens an iframe-type popup and I want it to show a hint that is as a property in that other .xml. The .xml is not included (there are many of those types) and they are loaded when I click on the hotspot.

  • if its just data then it is easier because it doesn't conflict with your main xml

    <krpano>

    <popup name="welcome" text="hello" />

    </krpano>

    but why not including everything from the beginning ? that would be much easier

    trace(popup[welcome].text);

    if you dont want that, includexml probably works

    includexml("popupinfo.xml", trace(popup[welcome].text));

  • In main.xml:

    In external_3000.xml:

    Code
    <scene name="scene_IMG_6221" title="Mytitle unique for 6221 bla bla">
    <view hlookat ... />
    <preview url ... />
    <image hfov="1.00" ... />
    </image>    
    </scene>

    The action "showtitleforexternalxml" is the one I need to program to obtain the "title" value from an external xml.

    There are thousands of external xml, I couldn't include them all, that's why I would like to get the value of the title property only when the cursor is over the hotspot

  • are these different panorama tours which are connected,

    and external_3000.xml is used by another tour as main xml?

    if you use loadxml/includexml that might mess up your main xml (depends on the xmls)

    if these files only contain scenes and there are no name conflicts it could work though..

    ...

    <action name="showtitleforexternalxml">
    includexml("external_3000.xml", trace(scene[scene_IMG_6221].title));
    </action>

  • Thanks very much index,

    Simplifying my question:
    main.xml contains a single hotspot
    that when clicked should display in the console the value of the title property of secondary.xml that contains a single scene with the title property
    There are no databases, just these two xml
    What would the code be?

    Note: secondary.xml is not initially included in main.xml

    Einmal editiert, zuletzt von Fernando (19. November 2023 um 18:30)

  • Fernando 19. November 2023 um 22:29

    Hat den Titel des Themas von „How to get property of external .xml“ zu „[SOLVED]How to get property of external .xml“ geändert.
  • Thanks very much Index, solved!! *thumbsup*

    The real example was a bit more complicated since it had to replace the name of the folder and the scene from the name of the hotspot and other hotspot property called folder.

    Result:

    Code
    <action name="showtitleforexternalxml">
    set(myscene,get(name));
    set(myfolder,get(folder));
    includexml(calc(lacarpeta + '/vtour/tour.xml'),
    set(mytitle,calc('scene[scene_' + get(myscene) +'].title'));
    trace('The title is ', get(mytitle));
    );
    </action>
  • Code
    <action name="showtitleforexternalxml">
    includexml(calc(lacarpeta + '/vtour/tour.xml'),
        copy(title, scene[calc('scene_' + name)].title);
        trace('The title is ', title);
    );
    </action>

    *thumbsup* (simplified code)

    note:

    a) the copy(title, .. part is executed after a tiny delay because the xml must get loaded first

    b) after including the data stays in memory

    c) you're including a tour.xml and all its settings, scenes, actions etc will get merged with your main xml.

    your main tour.xml might not work as intended anymore.

  • Hi Index, thank you very much for your advice and the code you suggested. *thumbsup*

    You are absolutely right and it has served as a learning experience for me. I tried to use information that existed in the popups for the hint of the main.xml but in order not to repeat information what I did was compromise the main.xml.

    In the real project I am going to add the hint information directly to the hotspots even though it is repeated. That would also help me identify the hotspots with something better than the name, that is, with a hint or description.

    Greets from Havana, Fernando

Jetzt mitmachen!

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