Populate text boxes using strings pulled from external XML

shiggins-9138
shiggins-9138 Community Member Posts: 9
Hi all
Is it possible to attach an external XML to a title and use JavaScript to pull strings from it into text boxes on the stage? If so, what is the best way to embed the XML into the title and parse it into the JS? This is for LMS integration, if it makes any difference.
Small words and simple steps appreciated
Thanks in advance

Comments

  • wheels
    wheels Florida USACommunity Member, Administrator, Moderator, Rockstar Manager Posts: 636 eLearning ROCKSTAR Admin Team
    I feel it might help if you start with what you are trying to achieve / what problem are you trying to solve.

    Here is a REALLY OLD video talking about dynamic text:
    https://www.trivantis.com/elearning-save-time-dynamic-text

    The idea is the same and we still have this feature, maybe this will be enough?
  • shiggins-9138
    shiggins-9138 Community Member Posts: 9
    Thanks Joe
    The aim is to create several language versions all contained within the same title where the text content can be populated based on the language choice and text updates can be made quickly to each version. I have seen the dyntitle.xml but I'm looking for a more user-friendly method (that file is particularly difficult to navigate quickly), where the text could be laid out like this...

    <Page1>
    <txt_1>
    <en>This box is first</en>
    <es>Es la primera</es>
    <fr>Celui-çi la boîte première</fr>
    </txt_1>
    <txt_2>
    <en>This box is second</en>
    <es>Es la secunda</es>
    <fr>Celui-çi la boîte deuxième</fr>
    </txt_2>
    </Page1>

    ...from which the JavaScript could select the appropriate content.

    My problem is that I can't seem to work out how to link the XML file to my JS through the Lectora storage

    Thanks again
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916 ☆ Roadie ☆
    Better use JSON or actually a database to get the texts. Have what you talk about working... using text from an external database ( actually from Google Slides ) Its my new workflow that makes completely dynamic titles, so indeed you can use it to create 1 title with any amount of languages ( actually even replace images with localized texts where and when needed )

    Alas i cannot share this as is...but i probably can make a sample for you that does this..

    What lectora version are you working in?
  • shiggins-9138
    shiggins-9138 Community Member Posts: 9
    Thanks for the suggestion, Math.
    We have considered JSON but we're not too familiar with it and XML would be much more in line with our current working style for the time being, so if it's achievable that way it would be preferable.

    The version, however, is Lectora Online 4.5

    Thanks again, though
  • mnotermans5114
    mnotermans5114 Community Member Posts: 916 ☆ Roadie ☆
    Created a simple setup that reads data from XML... as of cross-origin security i had to add it to my own site to test.
    With CORS you should be able to read it from anywhere...

    Here you see it working...
    http://www.mathnotermans.nl/TrivantisCommunity/

    And the Lectora Online package added...

    Regards,
    Math
  • shiggins-9138
    shiggins-9138 Community Member Posts: 9
    Hi Math
    Many thanks for this, although I keep getting this error:

    [readXMLFile( _path )] NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://www.mathnotermans.nl/TrivantisCommunity/data_simple.xml'.

    I've tried allowing for loading time, too, but still no luck.

    On another note, we've actually managed to put something in place ourselves in the Lectora title, but for some reason it seems to work in the Single Page Preview but not once exported, when we get this error:

    TypeError: Cannot set property 'innerHTML' of undefined

    Is there something in the wider package that would be causing this?

    Thanks again for your help