Link to home
Start Free TrialLog in
Avatar of CREATiVENESS
CREATiVENESSFlag for United States of America

asked on

How do I edit an two xml files with PHP?

I am using a php code to edit a single xml file to be read by jwplayer. Now I need to update it to edit two xml files, one will be read by html5 (specifically ios devices) and the other is read by flash. The flash version is using the code below and works fine, but I need to edit the html5 version to not include the
<jwplayer:provider>rtmp</jwplayer:provider>
<jwplayer:streamer>rtmp://mediasrv3.blahblah.net/arch</jwplayer:streamer>
and instead to include the code before the url
"http://mediasrv3.blahblah.net/arch/"
html5 doesnt read the rtmp.


For a little more explaining please see my first question
https://www.experts-exchange.com/questions/27115865/How-do-I-edit-an-xml-file-with-PHP.html

Any help is really appreciated.
Thanks
<?php
        
/*First check if user want to delete some item:*/        
if (isset($_POST['delEl'])) {
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;
    
//    set namespaces
    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

//    we search for items to delete
    foreach ($_POST['elToDel'] as $v) {
        $toDel = $xpath->query('//item')->item($v);
        $toDel->parentNode->removeChild($toDel);
    }
    $xml->save($xml_fname);
}

/*Here we check if user want to add an element and in this case we print the form to fill to add element*/
if (isset($_POST['addEl'])){
    echo "<img id='cms_orig_r3_c2' width='984' height='251' border='0' alt='' src='videocms/images_002b/cms_orig_r3_c2.jpg' name='cms_orig_r3_c2'><form id='' action='" . $_SERVER['PHP_SELF'] . "' name='form1' method='post'>";
    echo "<table bgcolor='#99CCFF'>";
    echo "<tr>";
    echo "<td>";
    echo "Title: <input type='text' name='itemtitle' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Subtitle: <input type='text' name='credit' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Content: <input type='text' name='content' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Thumbnail: <input type='text' name='thumbnail' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "<input type='submit' id='submitAdd' name='submitAdd' value='Add' />";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    echo "</form>";
    exit();
}

/*if form to add an element has been submitted we write new item to the file*/
if (isset($_POST['submitAdd'])) {
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    $channel = $xpath->query("//channel");
    $item = $xml->createElement('item');
    $channel->item(0)->appendChild($item);
    $elTitle = $xml->createElement('title');
    $item->appendChild($elTitle);
    $elTitle->appendChild($xml->createTextNode($_POST['itemtitle']));
    $media = $xml->createElement('media:credit');
    $item->appendChild($media);
    $media->setAttribute('role', 'author');
    $media->appendChild($xml->CreateTextNode($_POST['credit']));
    $media = $xml->createElement('media:content');
    $item->appendChild($media);
    $media->setAttribute('url', $_POST['content']);
    $media = $xml->createElement('media:thumbnail');
    $item->appendChild($media);
    $media->setAttribute('url', $_POST['thumbnail']);	
	$elprov = $xml->createElement('jwplayer:provider');
    $item->appendChild($elprov);
    $elprov->appendChild($xml->createTextNode('rtmp'));	
	$elstream = $xml->createElement('jwplayer:streamer');
    $item->appendChild($elstream);
    $elstream->appendChild($xml->createTextNode('rtmp://mediasrv3.blahblah.net/arch'));	
    $xml->formatOutput = true;
    $xml->save($xml_fname);
}


/*Here we check if user has submitted some change to the file*/
if (isset($_POST['editEl'])) {
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    for ($i = 0; $i < $xpath->query("//title")->length; $i++) {
        $xpath->query('//title')->item($i)->nodeValue = $_POST['title'][$i];
    }
    
    $i = 0;
    for ($i = 0; $i < $xpath->query("//c:credit")->length; $i++) {
        $xpath->query("//c:credit")->item($i)->nodeValue = $_POST['credit' . $i];
        $xpath->query("//c:content")->item($i)->setAttribute("url", $_POST['content' . $i]);
        $xpath->query("//c:thumbnail")->item($i)->setAttribute("url", $_POST['thumbnail' . $i]);
    }
    $xml->save($xml_fname);
	echo "<strong>Saved XML Results:</strong><br />";
    $i = 0;
    for ($i = 0; $i < $xpath->query("//c:credit")->length; $i++) {
        echo "<table width='600' border='0'>
          <tr bgcolor='#99CCFF' align='left'>
            <td>Subtitle: " . $xpath->query("//c:credit")->item($i)->nodeValue . "<br />";
        echo "video: " . $xpath->query("//c:content")->item($i)->getAttribute("url") . "<br />";
        echo "thumbnail: " . $xpath->query("//c:thumbnail")->item($i)->getAttribute("url") . "</td>
          </tr>
        </table><br />";
    }
}

    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    echo "<div id='container'><img id='cms_orig_r3_c2' width='984' height='251' border='0' alt='' src='videocms/images_002b/cms_orig_r3_c2.jpg' name='cms_orig_r3_c2'>";
    echo "<br />";

    echo "Document Title: " . $root->getElementsByTagName('title')->item(0)->nodeValue;
    echo "<br />";
    echo "<br />";

    $i = 0;
    echo "<form id='' action='" . $_SERVER['PHP_SELF'] . "' name='form1' method='post'>";
    echo "<div id='td-container'><table bgcolor='#e3e3e3' >";
    echo "<tr>";
    echo "<td colspan=5 style='padding:0 0 10px 40px;'>";
    echo "<span class='td-header'>Document Title: </span> <input type='text' name='title[]' value='" . $xpath->query("//title")->item(0)->nodeValue . "' />";
    echo "</td>";
    echo "</tr><tr bgcolor='#99ccff'>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>movie title</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>author</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>file</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>thumbnail</span></td>
    <td width='64' bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>delete</span></td>
  </tr>";
    for ($i = 0; $i < $xpath->query("//item")->length; $i++) {
        echo "<tr bgcolor='#99CCFF'>";
        
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='title[]" . $i . "' value='" . $xpath->query("//title")->item($i + 1)->nodeValue . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='credit" . $i . "' value='" . $xpath->query("//c:credit")->item($i)->nodeValue . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='content" . $i . "' value='" . $xpath->query("//c:content")->item($i)->getAttribute("url") . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='thumbnail" . $i . "' value='" . $xpath->query("//c:thumbnail")->item($i)->getAttribute("url") . "' /><br /><br />";
        echo "</td>";
		echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='checkbox' name='elToDel[]' value='$i' />";
        echo "</td>";
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td colspan=5>";
    echo "<input type='submit' id='editEl' name='editEl' value='Accept changes' />
        <input type='submit' id='delEl' name='delEl' value='Delete selected elements' />
        <input type='submit' id='addEl' name='addEl' value='Add a new element' />";
    echo "</td>";
    echo "</tr>";
    echo "</table></div>";
    echo "</form></div>";
?>

Open in new window

Avatar of sweetfa2
sweetfa2
Flag of Australia image

Remove lines 82-87

	$elprov = $xml->createElement('jwplayer:provider');
    $item->appendChild($elprov);
    $elprov->appendChild($xml->createTextNode('rtmp'));	
	$elstream = $xml->createElement('jwplayer:streamer');
    $item->appendChild($elstream);
    $elstream->appendChild($xml->createTextNode('rtmp://mediasrv3.blahblah.net/arch'));	

Open in new window


Not entirely clear what you wanted it replaced with - maybe nothing, who knows.

Anyhow most likely what you want to replace can go in the same place.
Avatar of CREATiVENESS

ASKER

thanks sweetfa but I need it to update the two files at the same time.
Are you looking to edit or create XML files?  I am not sure you need to remove anything for HTML5.  But I am sure that if we are going to help in any concrete way we would need to have the loadAndEdit.xml.
the loadandedit.xml file looks like this. I also need to edit the file loadandedit-html.xml that looks exactly like this but with the jwplayer lines.

<rss xmlns:jwplayer="http://developer.longtailvideo.com/trac/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Load-Edit-Test</title>
<item>
<title>AEC Town Hall Meeting</title>
<media:credit role="author">Randy</media:credit>
<media:content url="videos/hd/2185/36kil1vntk5uvq4auh1p4z7jbsl6e530.mp4"/>
<media:thumbnail url="playerlogo.jpg"/>
<jwplayer:provider>rtmp</jwplayer:provider> 
<jwplayer:streamer>rtmp://mediasrv3.blahblah.net/arch</jwplayer:streamer> 
</item>


<item>
<title>Video Test3</title>
<media:credit role="author">Randy</media:credit>
<media:content url="video.mp4"/>
<media:thumbnail url="playerlogo.jpg"/>
<jwplayer:provider>rtmp</jwplayer:provider> 
<jwplayer:streamer>rtmp://mediasrv3.blahblah.net/arch</jwplayer:streamer> 
</item>

</channel>
</rss>

Open in new window

sorry I meant without the jwplayer lines.

<jwplayer:provider>rtmp</jwplayer:provider>
<jwplayer:streamer>rtmp://mediasrv3.blahblah.net/arch</jwplayer:streamer>
Thanks.  Now what is the output you are looking for?  I am thinking that there is an easy string-based way to create these two XML files.
thanks Ray,
the files already exist, I just need to add a piece to the existing code that also updates another page (loadandedit-html.xml).

Duplicating the coding to include a new file but without the the lines mentioned above didnt seem like the best option.
What do you guys think?
Let me try this question again... what is the output you are looking for?  Please save our time and just post an example of the outputs you need to get.  There are many experienced programmers here at EE with ideas about how to bridge the gap from input strings to output strings.  XML is only a string of characters.  This is almost certainly easier than you think!
hi ray the second xml output should like like this


<rss xmlns:jwplayer="http://developer.longtailvideo.com/trac/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>Load-Edit-Test</title>
<item>
<title>AEC Town Hall Meeting</title>
<media:credit role="author">Randy</media:credit>
<media:content url="http://mediasrv3.blahblah.net/arch/videos/hd/2185/36kil1vntk5uvq4auh1p4z7jbsl6e530.mp4"/>
<media:thumbnail url="playerlogo.jpg"/>
</item>


<item>
<title>Video Test3</title>
<media:credit role="author">Randy</media:credit>
<media:content url="http://mediasrv3.blahblah.net/arch/videos/hd/2185/k5uvq4auh1p4z7jb.mp4"/>
<media:thumbnail url="playerlogo.jpg"/>
</item>
</channel>
</rss>

Open in new window

Thanks, I'll look at it in a moment and try to post back with the general design patter I would recommend.
Here is how I would do it - just simple strings of data.  

I dispensed with the forms in your script because I could not follow the naming convention from the form to the action script.  Instead I just made up a simulated POST array with three simulated lines of form data.  This is pretty much the way you would get input from a variable-length HTML form.  I hope this makes sense to you.   There may be some other parts you want to process, but the design pattern should be sound - just a few more lines of code to process the other data elements (see around lines 64-74).
http://www.laprbass.com/RAY_temp_creativeness.php

Best of luck with your project, ~Ray
<?php // RAY_temp_creativeness.php
error_reporting(E_ALL);


// UPDATE TWO DIFFERENT RSS FEEDS WITH THE SAME EXTERNAL FOR DATA


// SIMULATED FORM INPUT
$_POST = array
( 'channel_title' => 'MY CHANNEL'
, 'item_titles'   => array( 'ITEM1',  'ITEM2',  'ITEM3'  )
, 'media_urls'    => array( 'MEDIA1', 'MEDIA2', 'MEDIA3' )
)
;


// COMMON HEADER AND FOOTER FOR BOTH FEEDS
$header = <<<HEADER
<rss xmlns:jwplayer="http://developer.longtailvideo.com/trac/" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>CHANNEL_TITLE</title>
HEADER;

$footer = <<<FOOTER
</channel>
</rss>
FOOTER;



// ONE SET OF ITEM TAGS
$jwp_item_template = <<<JWP_ITEM_TEMPLATE
<item>
<title>ITEM_TITLE</title>
<media:credit role="author">Randy</media:credit>
<media:content url="MEDIA_URL"/>
<media:thumbnail url="playerlogo.jpg"/>
<jwplayer:provider>rtmp</jwplayer:provider>
<jwplayer:streamer>rtmp://mediasrv3.blahblah.net/arch</jwplayer:streamer>
</item>
JWP_ITEM_TEMPLATE;



// ANOTHER SET OF ITEM TAGS
$rss_item_template = <<<RSS_ITEM_TEMPLATE
<item>
<title>ITEM_TITLE</title>
<media:credit role="author">Randy</media:credit>
<media:content url="MEDIA_URL"/>
<media:thumbnail url="playerlogo.jpg"/>
</item>
RSS_ITEM_TEMPLATE;



// PROCESS THE CHANNELS
$jwp_out = str_replace('CHANNEL_TITLE', $_POST["channel_title"], $header) . PHP_EOL;
$rss_out = str_replace('CHANNEL_TITLE', $_POST["channel_title"], $header) . PHP_EOL;

// PROCESS THE ITEMS
foreach ($_POST["item_titles"] as $key => $item_title)
{
    $media_url = $_POST["media_urls"][$key];

    // COPY THE ITEM TEMPLATES AND INSERT THE POST DATA
    $jwp_item = $jwp_item_template;
    $jwp_item = str_replace('ITEM_TITLE', $item_title, $jwp_item);
    $jwp_item = str_replace('MEDIA_URL',  $media_url,  $jwp_item);

    $rss_item = $rss_item_template;
    $rss_item = str_replace('ITEM_TITLE', $item_title, $rss_item);
    $rss_item = str_replace('MEDIA_URL',  $media_url,  $rss_item);

    // APPEND THE ITEMS TO THE RESPECTIVE CHANNEL
    $jwp_out .= $jwp_item . PHP_EOL;
    $rss_out .= $rss_item . PHP_EOL;
}

// CLOSE THE CHANNELS
$jwp_out .= $footer;
$rss_out .= $footer;


// SHOW WHAT WE CREATED
echo "<pre>";
var_dump($_POST);
echo PHP_EOL;
echo htmlentities($jwp_out);
echo PHP_EOL . PHP_EOL;
echo htmlentities($rss_out);

Open in new window

Hi guys,
Im sorry Ray your coding was completely different from what I have already and didnt want to start over when I know this works. What I have done now is duplicate all the coding to include the html5 file but i am receiving this error

Warning: DOMDocument::save(loadAndEdit-html.xml) [domdocument.save]: failed to open stream: Permission denied in C:\Inetpub\vhosts\visitaec.com\httpdocs\testform2-rfa2.php on line 229

Any Ideas?
<?php
        
/*First check if user want to delete some item:*/        
if (isset($_POST['delEl'])) {
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;
	
	$xml2_fname = "loadAndEdit-html.xml";
    $xml2 = new DOMDocument();
    $xml2->load($xml2_fname);
    $root2 = $xml2->documentElement;
    
//    set namespaces
    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');
	
	$xpath2 = new DOMXPath($xml2);
    $xpath2->registerNamespace('c', 'http://search.yahoo.com/mrss/');

//    we search for items to delete
    foreach ($_POST['elToDel'] as $v) {
        $toDel = $xpath->query('//item')->item($v);
        $toDel->parentNode->removeChild($toDel);
		
		$toDel2 = $xpath2->query('//item')->item($v);
        $toDel2->parentNode->removeChild($toDel2);
    }
    $xml->save($xml_fname);
	$xml2->save($xml2_fname);
}

/*Here we check if user want to add an element and in this case we print the form to fill to add element*/
if (isset($_POST['addEl'])){
    echo "<img id='cms_orig_r3_c2' width='984' height='251' border='0' alt='' src='videocms/images_002b/cms_orig_r3_c2.jpg' name='cms_orig_r3_c2'><form id='' action='" . $_SERVER['PHP_SELF'] . "' name='form1' method='post'>";
    echo "<table bgcolor='#99CCFF'>";
    echo "<tr>";
    echo "<td>";
    echo "Title: <input type='text' name='itemtitle' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Subtitle: <input type='text' name='credit' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Content: <input type='text' name='content' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "Thumbnail: <input type='text' name='thumbnail' value='' /><br /><br />";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>";
    echo "<input type='submit' id='submitAdd' name='submitAdd' value='Add' />";
    echo "</td>";
    echo "</tr>";
    echo "</table>";
    echo "</form>";
    exit();
}

/*if form to add an element has been submitted we write new item to the file*/
if (isset($_POST['submitAdd'])) { 
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;
	
	$xml2_fname = "loadAndEdit-html.xml";
    $xml2 = new DOMDocument();
    $xml2->load($xml2_fname);
    $root2 = $xml2->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');
	
	$xpath2 = new DOMXPath($xml2);
    $xpath2->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    $channel = $xpath->query("//channel");
    $item = $xml->createElement('item');
    $channel->item(0)->appendChild($item);
    $elTitle = $xml->createElement('title');
    $item->appendChild($elTitle);
    $elTitle->appendChild($xml->createTextNode($_POST['itemtitle']));
    $media = $xml->createElement('media:credit');
    $item->appendChild($media);
    $media->setAttribute('role', 'author');
    $media->appendChild($xml->CreateTextNode($_POST['credit']));
    $media = $xml->createElement('media:content');
    $item->appendChild($media);
    $media->setAttribute('url', $_POST['content']);
    $media = $xml->createElement('media:thumbnail');
    $item->appendChild($media);
    $media->setAttribute('url', $_POST['thumbnail']);	
	$elprov = $xml->createElement('jwplayer:provider');
    $item->appendChild($elprov);
    $elprov->appendChild($xml->createTextNode('rtmp'));	
	$elstream = $xml->createElement('jwplayer:streamer');
    $item->appendChild($elstream);
    $elstream->appendChild($xml->createTextNode('rtmp://mediasrv3.praizevision.net/aecarch'));	
    $xml->formatOutput = true;
    $xml->save($xml_fname);
	
    $channel2 = $xpath2->query("//channel");
    $item2 = $xml2->createElement('item');
    $channel2->item(0)->appendChild($item2);
    $elTitle2 = $xml2->createElement('title');
    $item2->appendChild($elTitle2);
    $elTitle2->appendChild($xml2->createTextNode($_POST['itemtitle']));
    $media2 = $xml2->createElement('media:credit');
    $item2->appendChild($media2);
    $media2->setAttribute('role', 'author');
    $media2->appendChild($xml2->CreateTextNode($_POST['credit']));
    $media2 = $xml2->createElement('media:content');
    $item2->appendChild($media2);
    $media2->setAttribute('url', $_POST['content']);
    $media2 = $xml2->createElement('media:thumbnail');
	
    $xml2->formatOutput = true;
    $xml2->save($xml2_fname);	
}


/*Here we check if user has submitted some change to the file*/
if (isset($_POST['editEl'])) {
    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;

    $xml2_fname = "loadAndEdit-html.xml";
    $xml2 = new DOMDocument();
    $xml2->load($xml2_fname);
    $root2 = $xml2->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    $xpath2 = new DOMXPath($xml2);
    $xpath2->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    for ($i = 0; $i < $xpath->query("//title")->length; $i++) {
        $xpath->query('//title')->item($i)->nodeValue = $_POST['title'][$i];
        $xpath2->query('//title')->item($i)->nodeValue = $_POST['title'][$i];
    }
    
    $i = 0;
    for ($i = 0; $i < $xpath->query("//c:credit")->length; $i++) {
        $xpath->query("//c:credit")->item($i)->nodeValue = $_POST['credit' . $i];
        $xpath->query("//c:content")->item($i)->setAttribute("url", $_POST['content' . $i]);
        $xpath->query("//c:thumbnail")->item($i)->setAttribute("url", $_POST['thumbnail' . $i]);

        $xpath2->query("//c:credit")->item($i)->nodeValue = $_POST['credit' . $i];
        $xpath2->query("//c:content")->item($i)->setAttribute("url", $_POST['content' . $i]);
        $xpath2->query("//c:thumbnail")->item($i)->setAttribute("url", $_POST['thumbnail' . $i]);
    }
    $xml->save($xml_fname);
	$xml2->save($xml2_fname);
	echo "<strong>Saved XML Results:</strong><br />";
    $i = 0;
    for ($i = 0; $i < $xpath->query("//c:credit")->length; $i++) {
        echo "<table width='600' border='0'>
          <tr bgcolor='#99CCFF' align='left'>
            <td>Subtitle: " . $xpath->query("//c:credit")->item($i)->nodeValue . "<br />";
        echo "video: " . $xpath->query("//c:content")->item($i)->getAttribute("url") . "<br />";
        echo "thumbnail: " . $xpath->query("//c:thumbnail")->item($i)->getAttribute("url") . "</td>
          </tr>
        </table><br />";
    }
}

    $xml_fname = "loadAndEdit.xml";
    $xml = new DOMDocument();
    $xml->load($xml_fname);
    $root = $xml->documentElement;

    $xpath = new DOMXPath($xml);
    $xpath->registerNamespace('c', 'http://search.yahoo.com/mrss/');

    echo "<div id='container'><img id='cms_orig_r3_c2' width='984' height='251' border='0' alt='' src='videocms/images_002b/cms_orig_r3_c2.jpg' name='cms_orig_r3_c2'>";
    echo "<br />";

    echo "Document Title: " . $root->getElementsByTagName('title')->item(0)->nodeValue;
    echo "<br />";
    echo "<br />";

    $i = 0;
    echo "<form id='' action='" . $_SERVER['PHP_SELF'] . "' name='form1' method='post'>";
    echo "<div id='td-container'><table bgcolor='#e3e3e3' >";
    echo "<tr>";
    echo "<td colspan=5 style='padding:0 0 10px 40px;'>";
    echo "<span class='td-header'>Document Title: </span> <input type='text' name='title[]' value='" . $xpath->query("//title")->item(0)->nodeValue . "' />";
    echo "</td>";
    echo "</tr><tr bgcolor='#99ccff'>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>movie title</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>author</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>file</span></td>
    <td bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>thumbnail</span></td>
    <td width='64' bgcolor='#E3E3E3' style='padding:0 0 0 10px;'><span class='td-title'>delete</span></td>
  </tr>";
    for ($i = 0; $i < $xpath->query("//item")->length; $i++) {
        echo "<tr bgcolor='#99CCFF'>";
        
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='title[]" . $i . "' value='" . $xpath->query("//title")->item($i + 1)->nodeValue . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='credit" . $i . "' value='" . $xpath->query("//c:credit")->item($i)->nodeValue . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='content" . $i . "' value='" . $xpath->query("//c:content")->item($i)->getAttribute("url") . "' /><br /><br />";
        echo "</td>";
        echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='text' name='thumbnail" . $i . "' value='" . $xpath->query("//c:thumbnail")->item($i)->getAttribute("url") . "' /><br /><br />";
        echo "</td>";
		echo "<td bgcolor='#bed7f1' style='padding:10px 10px 10px 10px;'>";
        echo "<input type='checkbox' name='elToDel[]' value='$i' />";
        echo "</td>";
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td colspan=5>";
    echo "<input type='submit' id='editEl' name='editEl' value='Accept changes' />
        <input type='submit' id='delEl' name='delEl' value='Delete selected elements' />
        <input type='submit' id='addEl' name='addEl' value='Add a new element' />";
    echo "</td>";
    echo "</tr>";
    echo "</table></div>";
    echo "</form></div>";
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Ray,
I really appreciate your help, but i am very much a novice with php and your coding was to hard for me to follow. Its was different than the original coding that the EE user marqusG helped me with,
I also had to work with my other host so that this coding worked correctly (i am transferring the files to a new server when completely finished), so I apologize but going to new coding style isnt really possible.

The permissions was the issue also, I didnt know iI needed to change them.

The only issue left now is that I need to add a piece of the url to the output.
If you look at lines 120-121
I need to add
http://mediasrv3.blahblah.net/arch/
so that it writes
"http://mediasrv3.blahblah.net/arch/"+CreateTextNode($_POST['credit']

you are very good with strings so I hope you can help me with this.

Thanks,
Randy
Actaully I think the line is 123 that needs to be edited. What do you think.
I tried this
$media2->setAttribute('url', "http://mediasrv3.praizevision.net/aecarch/" + $_POST['content']);
but it doesnt work correctly,
Any Ideas?
Hi Guys,
Any ideas what im doing wrong here, im not sure what the coding above doesnt work. It acctually just puts a 0 in the xml instead of the correct info.

Thanks,
Randy
at line 125 I needed to add these two lines to include the thumbnail to the ios device xml file

$item2->appendChild($media2);
$media2->setAttribute('url', $_POST['thumbnail']);

But is there a way to write text before the Post here
$media2->setAttribute('url', $_POST['content']);

I need to add this url before the post info above  
http://mediasrv3.blahblah.net/arch/

Can i use the CreateTextNode or something to create a new address that looks like this
"http://mediasrv3.praizevision.net/aecarch/" + $_POST['content']

Thanks Guys,
Randy
So alls it needed was a ".", haha

so instead of
$media2->setAttribute('url', "http://mediasrv3.blahblah.net/arch/" + $_POST['content']);

I needed to use
$media2->setAttribute('url', "http://mediasrv3.blahblah.net/arch/" . $_POST['content']);
haha, thanks for the help.
Hey, thanks for the points - glad it's working out for you, ~Ray