Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing FCPXML in PHP

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
Using PHP I'm trying to figure out how to parse a Final Cut Pro X XML file, which seems to be different than standard XML, and have had no success so far. Ultimately I need to more finely tune the results but for now, just getting any results would be helpful! This gives nothing useful even though it seems to work on other XML files:

Code:
<?php
 $xml = simplexml_load_file("filename.fcpxml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child) {
   echo $child->getName() . ": " . $child . "<br />";
   }
 ?>

Has anyone worked with FCPXML who can offer help? It is mainly the <title> area I want to fetch but getting any results is a good start. Ideas?

Thanks.

Don
 
I would have thought so too and there are no HTML entities at all in the text but yet it comes out as a jumble when using

Code:
echo count($t->find('text')) > 0 ? $t->find('text')->text() : 'No text node' . "\n\n";

I did not try it with $t->find('text')->html though as it's working fine as it is.

However, I have one last question. I created a function called format_time() to convert the timestamps but I seem unable to pass values to it. If I call the function with them hard-code like this

Code:
echo format_time("216073858/60000s", "220220/60000s", "956956/60000s");

it works but not when I pass them as variables from the code below. My question is: is there some reason why parsed data values cannot be given variable names?

Code:
$i = 1;

require_once 'phpQuery.php';
phpQuery::newDocumentFileXML($xmlUrl, $charset='utf-8');

foreach (pq('project') as $project) {
	foreach(pq($project)->find('title') as $title) {
		$t = pq($title);
   		if ($t->attr('role') == 'Subtitles') {
			echo $i++ ."\r";
			$start = $t->attr('start');
			$duration = $t->attr('duration');
			$offset = $t->attr('offset');
			format_time($start, $duration, $offset) . "\n";
			echo $t->find('text')->text . "\n\n";
		}
	}
}

The function itself isn't giving the needed values yet and isn't the current problem so I'll refrain from bogging down the question unnecessarily by posting it here.
 
Oops! Never mind my question! It was a stupid mistake of not echoing the function so of course it wasn't appearing:

Code:
foreach (pq('project') as $project) {
	foreach(pq($project)->find('title') as $title) {
		$t = pq($title);
   		if ($t->attr('role') == 'Subtitles') {
			echo $i++ ."\r";
			$start = $t->attr('start');
			$duration = $t->attr('duration');
			$offset = $t->attr('offset');
			[red][b]echo[/b][/red] format_time($start, $duration, $offset) . "\n";
			echo $t->find('text')->text . "\n\n";

		}
	}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top