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

0 favourites
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • 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.

  • 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).

  • 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:

    or maybe the problem is my XML file:

    <?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>[/code:d72d3346]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

  • Thanks

    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)

  • 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.

  • 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

  • something like this?

    demo2video.capx

  • Thanks 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?

  • Up

  • I store information in array because I do not want to display full path to video..

    let's say you have on server something like this..

    you can use list.php to get all sub-folders and files in video folder

    <?php
    function listFolderFiles($dir){
        $ffs = scandir($dir);
       
        foreach($ffs as $ff){
            if($ff != '.' && $ff != '..'){
               echo $ff. PHP_EOL;
             if(is_dir($dir.'/'.$ff)) listFolderFiles($dir.'/'.$ff);}}}
    
    listFolderFiles('video');
    exit;
    ?>[/code:ewugl4oe]
    so..your ajax data will look like this:
    [img="http://lookpic.com/O/i2/1364/e8EIVxSr.png"]
    
    now you can loop through data and populate array and list object..
    
    [url=https://app.box.com/s/nozesa4msrfq346aoohpq8ovmaicxvic]phpDir2List.capx[/url]
    
    if you upload a new videos or delete..even sub-folders in [b]videos/video[/b] folder..
    you do not have to make any changes in php script or C2 code...
  • Thank you for this solution and for all the explanation,

    The problem is that is an offline project (CD/DVD). In this demonstration that I'm developing to a possible client, the user will can see a video or image preview and play sounds, clicking in the list items. They intend to use a program that capture the folder content and convert it to the CSV files that contains "name" and "path", like the file that I have included in the example. This is the main reason that I insisting in to use a CSV file.

  • Up

  • Mon Sep 19, 2016 10:11 pm

    The problem is that is an offline project ...

    Sat Sep 17, 2016 9:18 pm

    ...because is the file that will be updated on the server ...

    ...mmm...nevermind...

    CSV files that contains "name" and "path", like the file that I have included in the example.

    Your Example:

    Videos.csv (one line..)

    "path"= \videos\video.mp4

    & anime is "name"..of what? ..folder?..sub-folder?

    because it certainly is not the name of the video...

    you want to show in list anime & Play video.mp4 ??!

    ..nevermind..

    Here's how to separate CSV data..

    listCSV.capx

  • > Mon Sep 19, 2016 10:11 pm

    > The problem is that is an offline project ...

    >

    > ...because is the file that will be updated on the server ...

    >

    Sorry about that. I meant: on the folder.

    > CSV files that contains "name" and "path", like the file that I have included in the example.

    >

    > Your Example:

    > Videos.csv (one line..)

    >

    > "path"= \videos\video.mp4

    > & anime is "name"..of what? ..folder?..sub-folder?

    > because it certainly is not the name of the video...

    >

    > you want to show in list anime & Play video.mp4 ??!

    >

    > ..nevermind..

    >

    Yes, "anime" is just a name. I would like to show "anime" in the list and play video.mp4 or anime.mp4 when the user click in this item.

    Here's how to separate CSV data..

    listCSV.capx

    Thanks. I will give it a try.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)