View Full Version : Trying to get JAVA to read XML file paths

Jun 12th, 2006, 09:28 PM
Hey --

I'm very new to this, so please type slow. I'm working in a Mac environment and am trying to get data parsed out of XML via a PHP5 script into JSON to be read by a JAVA script.


Here's the problem I think I'm running into... The file paths aren't compatible. Something about absolute URI and kind-of-absoluteURI?? Somewhere the problem is with /localhost\

Here's what's happening with my JSON information:

If a file parsed is on my system drive I get:

If a file parsed was on a different drive than my system drive I get:

both are cool... tells ME exactly where those files were... but I need it to be able to tell JAVA where those files are. I'm thinking again the problem is in localhost.

Is there a code to drop localhost or replace localhost?

Thoughts? I really appreciate any help here and understand how busy everyone is.



Oh -- or am I an idiot for thinking that JAVA can't parse and deliver XML data by itself???

Jun 12th, 2006, 10:02 PM
JAVA and JavaScript are two entirely different beasts. Don't confuse them. It's not JAVA script, it's JavaScript, or if you like ECMAScript (the standard that it is based on)

Anyway, JavaScript can indeed read XML, it doesn't have to be JSON, it's just that XML has so much overhead. But if you've got it in XML already, you could definitely process it in the JavaScript.

As for your paths, well, if someone not on your computer tries to access localhost, they will access they're own computer, so that wont' work, in PHP try str_replace("localhost", "yourdomain.com", $fileurl);

However, I don't quite understand how you're getting file://localhost/whatever the file:// protocol, as I remember, is only for accessing local files, so if outside people need this, you'll need to replace file://localhost with http://www.mydomain.com/

Jun 12th, 2006, 10:34 PM
Thanks for MY syntax errors!! (hehe) But you just confused me even more. Let's get to that later.

Here's more information on what I want I'm trying to do:

I've got a program that I can export project information as XML. This is useful when you are trying to share projects between computers. But it also holds all the data I need in ANOTHER program that doesn't talk XML, but Java... or javascript (hence my confusion.) What I ultimately need to be able to do is write a .jsx script to grab the data out of the XML (not all of it... just the parts I want...) and then parse it to something JAVASCRIPT understands and then can be read by this new program as an executable script inside this program.

So -- no, it isn't web based at all. The app (when it gets that far...) will sit on a single user's computer and be used from there. So I guess I'm getting the LOCALHOST because I'm trying to do the first step in PHP? I just want a normal file path. I should post the XML path and show you what it looks like in there, but I stepped away from my home. I'll get it up if it makes a difference.

Do you still think this can be done with javascript?

Thanks again for your help.


Oh -- BTW - I was able to get the files into the second program by changing /localhost\ to /root\ in BBEdit (yuk, another step) -- but that caused other problems later in the script... I'll address those later once I figure out this part... or they already existed there an I just finally GOT the script to get that far.

Jun 13th, 2006, 04:13 PM
It sounds to me like your major problem is getting the file with PHP. What javascript help do you need?

Are you getting errors in your script? Can you post your code?

Jun 13th, 2006, 08:50 PM
AJAX will help you to get data parsed from an XML file


Jun 13th, 2006, 09:12 PM
Thanks, KOR -- I'll look into that... however... here's some code:

The Javascript for importing the JSON data

/*Pulls the JSON file

var pfile = fileGetDialo[/COLOR][/COLOR]g("Select a json file.", "TEXT");

if (pfile == null){
alert("No json file selected. ");

var readData = pfile.open("r","TEXT", "????");
var encoded_data = pfile.read();
alert("Problems reading JSON file");

var decoded_data = eval(encoded_data);

var myProject = app.newProject();
var myProject = app.project;

//grab the data that's important

for(x in decoded_data){

var sequenceName = decoded_data[x].sequence.name;
var sequenceHeight = decoded_data[x].sequence.height;
var sequenceWidth = decoded_data[x].sequence.width;
var sequenceRate = decoded_data[x].sequence.rate;
var sequenceDuration = decoded_data[x].sequence.duration / sequenceRate;
//.9 = D1 comp, I've hard coded a float value rather than coerce <pixelaspectratio>NTSC-CCIR-601</pixelaspectratio>
var myComp = myProject.items.addComp(sequenceName , sequenceWidth, sequenceHeight, .9, sequenceDuration, sequenceRate);

var layerCollection = myComp.layers;

//import footage

for(y in decoded_data[x]){

var os = system.osName;

// we need the path sans localhost, etc -- but it never actually removes localhost!!
if(os == 'MacOS'){
var fileRef = decoded_data[x][y].clip.path;
if(fileRef.indexOf('Volumes') != -1){
//on full hd path
var pathStart = 'Volumes';

var fileSubstring = fileRef.substring(fileRef.indexOf(pathStart) + pathStart.length, fileRef.length);

//Keeps breaking down here!! -- never gets to Insert footage ln73!!

var my_io = new ImportOptions(new File(fileSubstring));
var myItem = myProject.importFile(my_io);



//insert footage

var items = myProject.items;
var allFootage = new Array();

//run backwards to keep layer position
for (var i = items.length; i > 0; i--){
if (items[i].typeName == "Footage"){ // Retrieve only footage items
allFootage[allFootage.length] = items[i];

for(x in allFootage){


//position footage

var layerIterator = 1;
for(x in decoded_data){
for(place in decoded_data[x]){
var start = decoded_data[x][place].clip.start / sequenceRate ;
var end = decoded_data[x][place].clip.end / sequenceRate ;
var duration = decoded_data[x][place].clip.duration;

//check for a cut

if((decoded_data[x][place].clip.end - decoded_data[x][place].clip.start) != duration){

var fcpin = decoded_data[x][place].clip.fcpin;
var fcpout = decoded_data[x][place].clip.fcpout;
var cutStart = start - (duration - fcpin) / sequenceRate;
myComp.layer(layerIterator).startTime = cutStart;
myComp.layer(layerIterator).inPoint = cutStart + fcpin / sequenceRate;
myComp.layer(layerIterator).outPoint = cutStart + fcpout / sequenceRate;
myComp.layer(layerIterator).startTime = start;



Here's the data pulled directly from the PHP code:

[{"sequence":{"name":"XML to AE","duration":5265,"rate":30,"height":480,"width":720}},[{"clip":{"name":"TBPLux4.mov","path":"file:\/\/localhost\/Users\/captmench\/Movies\/TBPLux4.mov","start":0,"end":289,"fcpin":0,"fcpout":289,"duration":309}},{"clip":{"name":"ZacharyMessing","path":"file:\/\/localhost\/Volumes\/NATHAN\/TahoeProject\/Capture%20Scratch\/Birthdays06\/ZacharyMessing","start":289,"end":1144,"fcpin":2432,"fcpout":3287,"duration":13818}},{"clip":{"name":"ZacharyMessing","path":"","start":1144,"end":1285,"fcpin":10999,"fcpout":11140,"duration":0}},{"clip":{"name":"ZacharyMessing","path":"","start":1285,"end":2794,"fcpin":5767,"fcpout":7276,"duration":0}},{"clip":{"name":"ZacharyMessing","path":"","start":2794,"end":3187,"fcpin":12970,"fcpout":13363,"duration":0}},{"clip":{"name":"ZacharyMessing","path":"","start":3187,"end":4010,"fcpin":7551,"fcpout":8374,"duration":0}},{"clip":{"name":"ZacharyMessing","path":"","start":4010,"end":4342,"fcpin":13454,"fcpout":13786,"duration":0}},{"clip":{"name":"ZacharyMessing","path":"","start":4342,"end":-1,"fcpin":9833,"fcpout":10756,"duration":0}}]]


But it works BEST when I go in and remove /localhost\ and just leave it blank... but then it breaks after it imports footage.

I hope this putting the code in here works.



Jun 13th, 2006, 10:13 PM
Kor --

I really don't think AJAX is my answer. The end game is to get this last program to run it's internal scripter with this Javascript .jsx file.

Get it all done in AJAX and echo it out as a .jsx file... hmmm


Jun 14th, 2006, 07:39 AM
It's not a problem of AJAX (but it would be if you want to run it locally) it is a problem of XML vs. JSON. JSON is document/object oriented while XML is data oriented.

Now if you have already an XML, you don't need to transform it in a JSON, you may grab it as it is in a HTML or XHTML file:


Jun 14th, 2006, 04:55 PM
Thanks for the links... looks promising!

I'll try loading some of that into the front end of my .jsx script and see if I can't make it work straight out.