[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 908
  • Last Modified:

Parse and Load XML using PHP , Listbox , Textbox

Hi

I'm quite new to PHP programing and I need help / code for the following.

I have attached XML file that I need to parse see attached.

I need to parse it and build in HTML:

1. Listbox to show all the Descriptions

Once I click on any description in the Listbox following happens:
a. Lang listbox is populated/selected with relevant language (possible 4 , can be less used) (multiselection)
b. URL textbox is populated
c. Desc textbox is populated

2. User will be able to update the information

3. User can delete the movie

4. User will be able to save it back to the xml file all the changes that were done.

Only XML as DB allowed.

Any ideas/code. (Giving a lot of points here :-) )

Thank you.
Evgeny (evgeny.gol@gmail.com)
<?xml version="1.0" encoding="ISO-8859-1"?>
<videos>
<video url="http://www.youtube.com/v/QDQSUS3dUZg" lang="English,Russian,Hebrew,French" desc="Fish Tank" />
<video url="http://www.youtube.com/v/AfhT3Jui5jk" lang="English,Russian,Hebrew" desc="Jirenosvksi" />
</videos>

Open in new window

0
jekaman
Asked:
jekaman
  • 3
  • 2
1 Solution
 
jausionsCommented:
If you're using PHP5, use SimpleXML to parse the XML document and extract the values. Use explode() function to know which "lang" where selected.

To save the data, you can either use the DOM extension, or simply write the XML.

When writing to a file, make sure you lock it first using the flock() function.
0
 
jekamanAuthor Commented:
Can you create a short sample ?
0
 
jausionsCommented:
Check Example #5 "Using attributes" here: http://www.php.net/manual/en/simplexml.examples.php
0
 
jekamanAuthor Commented:
I know how to parse the XML file , but I need a little help how to PARSE and load the valies to the list/textbox.
0
 
jausionsCommented:
Here's something that should get you in the right direction. (I had it done yesterday, but Expert-Exchange was doing maintenance)
<?php
 
$xmlstr = '<?xml version="1.0" encoding="ISO-8859-1"?>
<videos>
<video url="http://www.youtube.com/v/QDQSUS3dUZg" lang="English,Russian,Hebrew,French" desc="Fish Tank" />
<video url="http://www.youtube.com/v/AfhT3Jui5jk" lang="English,Russian,Hebrew" desc="Jirenosvksi" />
</videos>';
 
$xml = new SimpleXMLElement($xmlstr);
 
$langs = array('English', 'Russian', 'Hebrew', 'French');
 
?>
<form action="blah.php" method="POST">
<?php
$i = 0;
foreach ($xml->video as $video) {
    $url = htmlspecialchars((string)$video['url']);
    $desc = htmlspecialchars((string)$video['desc']);
    $lang = explode(',', (string)$video['lang']);
 
    echo '<p><input type="text" name="url['.$i.']" value="'.$url.'" />
             <textearea name="desc['.$i.']">'.$desc.'</textarea>
             <select multiple="multiple" name="lang['.$i.'][]">';
    foreach ($langs as $l) {
        $selected = (in_array($l, $lang)) ? ' selected="selected"' : '';
        echo '<option value="'.$l.'"'.$selected.'>'.$l.'</option>';
    }
    echo '</select></p>';
    ++$i;
}
?>
</form>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now