Sie sind nicht angemeldet.

herrpedro

Schüler

  • »herrpedro« ist der Autor dieses Themas

Beiträge: 131

Wohnort: Lisbon

Beruf: Programmer/analyst

  • Nachricht senden

1

Dienstag, 25. September 2018, 22:37

parsing and accessing custom XML

hi all


i have some items showing in a vtour.
i'm making it multilanguage so i need several string according to language so i thought of a xtructure like this
accessing "data" is easy data[nameOne] will do it
data[nameOne].content will give me the inside
data[nameOne].sound will give me the sound

but i can't find a way to access the language node so i cent get the .content inside (and have my string)
<language name="pt">
portugues
</language>




<data name="nameOne" sound="somesound" video="somevideo" photo="somephoto">
<language name="pt">
portugues
</language>
<language name="en">
english
</language>
<language name="es">
espanõl
</language>
</data>

<data name="nameTwo" sound="somesound" video="somevideo" photo="somephoto">
<language name="pt">
portugues
</language>
<language name="en">
english
</language>
<language name="es">
espanõl
</language>
</data>

thank you for the help

2

Mittwoch, 26. September 2018, 22:22

You can use this example, hope it will work.

<data name="css_def">
<![CDATA[
write smth here
]]>

</data>

herrpedro

Schüler

  • »herrpedro« ist der Autor dieses Themas

Beiträge: 131

Wohnort: Lisbon

Beruf: Programmer/analyst

  • Nachricht senden

3

Mittwoch, 26. September 2018, 23:00

hi!
thank you for your 1st post :) welcome

i want something like data[nameOne].xml.language[pt].content or something like this <- edited: does not work either
so i can read the string "portugues" from that xml
i never tried this one.. i'll try it now :)

<data name="nameOne" sound="somesound" video="somevideo" photo="somephoto">
<language name="pt">
portugues
</language>
<language name="en">
english
</language>
<language name="es">
espanõl
</language>
</data>

4

Freitag, 28. September 2018, 22:42

Hi,

the <data> element is a special one, it's inner content doesn't get parsed, it will be stored as data[name].content.

Please see here for more:
https://krpano.com/docu/xml/#data

If you want to access the xml-parsed and to objects resolved elements use an other name for your xml element, e.g. <mydata>.

Best regards,
Klaus

herrpedro

Schüler

  • »herrpedro« ist der Autor dieses Themas

Beiträge: 131

Wohnort: Lisbon

Beruf: Programmer/analyst

  • Nachricht senden

5

Freitag, 28. September 2018, 22:43

hi!

that really really explains it.

thank you for your help

6

Sonntag, 30. September 2018, 22:29

Hi herrpedro,

Last year I posted my solution of multilanguage version of krpano here:
https://krpano.com/forum/wbb/index.php?p…5255&highlight=

It was done for the krpano ver 1.19.pr13. I do use it since then though I am planning to upgrade the code for the ver. 1.19.pr16. It's working as is in the ver. 1.19.pr16, too.
e.g. here
Some guys downloaded it but no feedback. Maybe you will be the first one.

Enjoy,
Pavel

herrpedro

Schüler

  • »herrpedro« ist der Autor dieses Themas

Beiträge: 131

Wohnort: Lisbon

Beruf: Programmer/analyst

  • Nachricht senden

7

Sonntag, 30. September 2018, 22:41

hi,

thank you for your reply,

i did read your post while working on this and searching the forum, i did it more than once actually

The thing is i'm after more than "translation".. i'm setting up hotspots and actions and dynamic hotspots based on that
like "youtube movie id" associated with language
or mp3 audio file associated to language

i managed to parse it already with klaus hint
now i'm having trouble with "defaults" or "fallback"

like.. if i want a "youtubeid" from a element i'm having trouble with "if" statements determining if a variable is there or not

if i want a sound i'll say "give sound associated with mydata[nameone] for english-UK"

the action will
see if there is a sound atribute associated with language en-uk
if not - see if there is a sound atribute associated with language for en
if not - see if there is a sound associated with the mydata element
if not.. return null

i cant do it with if === null or if != null or... tried so many variants i cant tell them all :D
so far i'm defaulting to
-> see if there is a sound atribute associated with language for en
and so i'm must be aware to fill in the xml for all languages (instead of only the top one if the string is the same for every one)

again, thank you for your help

8

Sonntag, 30. September 2018, 23:13

The new calc() function is really a powerful instrument!
I use it a lot e.g.
set( element,
attribute1=calc( isworking == true ? 'text1' + variable1 : 'text2' + variable2),
attribute2=calc( myHight LE 6 ? true : false),
...
);
You can nest the trinary operator, but the readibility of the code goes down.
I'm learning a lot from Klaus' 1.19.pr16 example of the combobox.xml. Thank you, Klaus for such a great lesson!

Pavel