How do I read a XML and create a list with a preview

Get help using Construct 2

Post » Thu Sep 15, 2016 10:47 am

I intend to create a demonstration that will be used to show and preview graphic/sound files that will stored in distinct folders.

Is it possible to read a XML file and show different lists (according with the media) that the user can select the item and see or listen a preview? If so, can someone explain to me what I need to do to get it working?

Anyone knows how can I populate a XML file with the folders content, automatically?

Thanks in advance.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Thu Sep 15, 2016 10:58 am

XML is explained in the manual and you can also check out this other example of use making an XML file for dialogs and displaying them.

In your case you will need to use the content of the XML to create your list in the list object, shouldn't be too hard (in regards to the tutorial and changing the display from a text object to a loop creating list items/indexes)
Also check the How do I FAQ at the category "List" for examples of use out of an array which can be adapted to your needs though.

For displaying "media", as long as it is an image, I guess you could use the "Load image from URL" action from a dedicated sprite object to display the selected picture (as long as your xml would contain the appropriate URL for the image to display).
Other medias like sound, I'm afraid cannot be dynamically streamed that way (not that I know of at least).
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,313
Reputation: 71,094

Post » Thu Sep 15, 2016 12:42 pm

Thanks for all the suggestions. I have checked it and I think the solution is to use XML plugin with Ajax and use tokenat to populate the list. But something is wrong in my script because the list keeps empty:

Image

or maybe the problem is my XML file:

Code: Select all
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<?fr-application created="FastReport"?>
<?fr-application homesite="http://www.fast-report.com"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Title></Title>
<Author></Author>
<Version>...</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Worksheet ss:Name="ReportPage1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="9" x:FullColumns="1" x:FullRows="1">
<Column ss:AutoFitWidth="0" ss:Width="94.49"/>
<Column ss:AutoFitWidth="0" ss:Width="354.33"/>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">anime</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\anime.avi</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">anime</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\anime.flv</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">green</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\green.avi</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">green</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\green.flv</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">Mov</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\Mov.avi</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">Mov</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\Mov.flv</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">life</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\life.avi</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
<Row ss:Height="13.08">
<Cell ss:Index="1" >
<Data ss:Type="String">life</Data>
</Cell>
<Cell ss:Index="2" >
<Data ss:Type="String">\videos\life.flv</Data>
</Cell>
<Cell ss:Index="3" />
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<PageMargins x:Bottom="0.38" x:Left="0.38" x:Right="0.38" x:Top="0.38"/>
</PageSetup>
</WorksheetOptions>
</Worksheet>
</Workbook>
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Thu Sep 15, 2016 1:20 pm

The point of using the XML plugin is to have it get the data for you. Here's an example from just the other day:
viewtopic.php?f=147&t=181788&p=1067666#p1067666
and a tutorial from a while back:
https://www.scirra.com/tutorials/354/xml-parsing
ImageImageImage
B
71
S
22
G
249
Posts: 3,764
Reputation: 138,579

Post » Thu Sep 15, 2016 2:59 pm

Thanks @Blackhornet.

This tutorial is very didactic. Do you know how can I get the "nodes" from my XML? This XML was generated by a program that capture the folder's content and save it in excel format. I can read the file now and include all this data in the list, but I need to isolate a specific content of this XML. (e.g.. "anime" to appear in the list and "\videos\anime.avi" to load and show the video).

EDITED: Can I use this solution with a CSV file instead a XML? (I think I will need to change XML plugin for another)
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Fri Sep 16, 2016 2:06 am

I've played with this and the XML parser doesn't like the namespaces. There is a CSV plugin available, so that might be an option. Or just manual RegEx.
ImageImageImage
B
71
S
22
G
249
Posts: 3,764
Reputation: 138,579

Post » Fri Sep 16, 2016 3:15 pm

Tha Ajax read CSV file. I don't know how to separate the two columns items, showing the 1st item (name) in the list and when the user click on it, open the video referent to the path (2nd item).

Simple example: https://www.dropbox.com/s/8t5qru7m7487o ... .capx?dl=0
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Fri Sep 16, 2016 7:58 pm

something like this?

demo2video.capx
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Fri Sep 16, 2016 10:11 pm

Thanks @korbaach. It's very nice but the problem is that I need the application reads the CSV because is the file that will be updated on the server. Can I use this solution with the CSV file instead the array?
Last edited by RBuster on Sat Sep 17, 2016 9:18 pm, edited 1 time in total.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Sat Sep 17, 2016 9:17 pm

Up
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Next

Return to How do I....?

Who is online

Users browsing this forum: jezjones24 and 17 guests