How do I load the following XML...

Get help using Construct 2

Post » Thu Jul 09, 2015 4:41 am

Hello community,

I am having trouble loading the XML below through the XML object. On import, i get multiple syntax errors and it will not load. On paper it seems to be a straight forward process but i might be missing something. @Ashley , @Yann Can you please confirm if this XML can be imported through the native XML object. If not, is there an alternative way to grab the data. The goal is for the hosted game to load the xml from an URL on runtime, grab and parse the data. Thank you in advanced for the assistance provided...


Code: Select all
<?xml version="1.0"?>
<words>
<meta>
<user_id>85826</user_id>
<word_order>e</word_order>
</meta>
<word>
<word>
<![CDATA[ flip-flop ]]>
</word>
<definition>
<![CDATA[ a thonged sandal and its clicking sound ]]>
</definition>
<wordid>
<![CDATA[ 367925 ]]>
</wordid>
<sentenceid>
<![CDATA[ 653737 ]]>
</sentenceid>
<soundfile>
<![CDATA[ /sounds/f/flip_flop.mp3 ]]>
</soundfile>
<definitionfile>
<![CDATA[ /definitionSounds/f/flip-flop_50d41874a9c93.mp3 ]]>
</definitionfile>
<definition_option id="460293" soundfile="/sounds/s/st_.mp3">
<![CDATA[ St. ]]>
</definition_option>
<definition_option id="310953" soundfile="/sounds/i/it_s.mp3">
<![CDATA[ it's ]]>
</definition_option>
<definition_option id="653737" soundfile="/sounds/f/flip_flop.mp3">
<![CDATA[ flip-flop ]]>
</definition_option>
</word>
<word>
<word>
<![CDATA[ it's ]]>
</word>
<definition>
<![CDATA[ contraction of "it is" ]]>
</definition>
<wordid>
<![CDATA[ 13637 ]]>
</wordid>
<sentenceid>
<![CDATA[ 310953 ]]>
</sentenceid>
<soundfile>
<![CDATA[ /sounds/i/it_s.mp3 ]]>
</soundfile>
<definitionfile>
<![CDATA[ /definitionSounds/i/it_s_50cb3fe723f2d.mp3 ]]>
</definitionfile>
<definition_option id="653737" soundfile="/sounds/f/flip_flop.mp3">
<![CDATA[ flip-flop ]]>
</definition_option>
<definition_option id="310953" soundfile="/sounds/i/it_s.mp3">
<![CDATA[ it's ]]>
</definition_option>
<definition_option id="460293" soundfile="/sounds/s/st_.mp3">
<![CDATA[ St. ]]>
</definition_option>
</word>
<word>
<word>
<![CDATA[ St. ]]>
</word>
<definition>
<![CDATA[ abbreviation for "street" ]]>
</definition>
<wordid>
<![CDATA[ 29966 ]]>
</wordid>
<sentenceid>
<![CDATA[ 460293 ]]>
</sentenceid>
<soundfile>
<![CDATA[ /sounds/s/st_.mp3 ]]>
</soundfile>
<definitionfile>
<![CDATA[ /definitionSounds/s/St._50cb531accd9f.mp3 ]]>
</definitionfile>
<definition_option id="653737" soundfile="/sounds/f/flip_flop.mp3">
<![CDATA[ flip-flop ]]>
</definition_option>
<definition_option id="310953" soundfile="/sounds/i/it_s.mp3">
<![CDATA[ it's ]]>
</definition_option>
<definition_option id="460293" soundfile="/sounds/s/st_.mp3">
<![CDATA[ St. ]]>
</definition_option>
</word>
</words>
B
106
S
20
G
8
Posts: 155
Reputation: 11,716

Post » Thu Jul 09, 2015 4:55 am

If you are loading through the C2 GUI, all quotes have to be doubled.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Thu Jul 09, 2015 9:25 am

As blackhornet said.
Also, I do have some XML file in a project as project file (so through AJAX, not directly inserted into C2's field) and comments starts with <!-- and close with --> in it.
You might want to check that out as well.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,287

Post » Thu Jul 09, 2015 10:47 am

You should definitely import files as project files and request them via AJAX. Pasting large amounts of data in to expressions has significant pitfalls and also requires extensive escaping of the data to stop the double-quotes ending the string, which is a really tedious problem to fix.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,694

Post » Thu Jul 09, 2015 3:47 pm

Thanks for the assistance @Blackhornet & @Ashley . Unfortunately, the project requires that the XML loads through an URL as there are 100's based on the game category and they are generated through an API.

@Kyatric Where can i find the XML project you mentioned?. I search through the forums and tutorials with no luck. Can you point me to the right location. It appears that it will assist me with the parsing of the data...
B
106
S
20
G
8
Posts: 155
Reputation: 11,716

Post » Thu Jul 09, 2015 5:51 pm

The XML file is part of a project of mine, it's not public.
Project files though are talked about in this tutorial.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
289
S
112
G
94
Posts: 7,333
Reputation: 69,287

Post » Thu Jul 09, 2015 6:02 pm

As a side note, the XML can indeed be loaded inside the official XML plugin. Just tried it !
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Thu Jul 09, 2015 9:00 pm

Thanks @Kyatric i will look again at this tutorial.

@Magistross, can you please share how you were able to do it? I was able to import the data through the AJAX object but have not been able through the official XML plugin directly . Is it possible for you to upload the .CAPX. to share with the community. I would be thankful as i know this has come up on many instances in the forum...
B
106
S
20
G
8
Posts: 155
Reputation: 11,716

Post » Thu Jul 09, 2015 9:36 pm

Sure, here it is.

https://dl.dropboxusercontent.com/u/700 ... adXML.capx

As an exemple, I displayed the first <word> node of the first <word> node. Strange document structure by the way, but I guess it's out of your control... :P
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Mon Jul 13, 2015 9:10 pm

Thank you @Magistross for taking the time to upload the sample and for everyone else who assisted. I was able to find a solution by using both the AJAX and XML object as shown.
B
106
S
20
G
8
Posts: 155
Reputation: 11,716


Return to How do I....?

Who is online

Users browsing this forum: Cryptwalker, Yahoo [Bot] and 4 guests