Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2009, 08:58 PM   PM User | #1
tensai
New to the CF scene

 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
tensai is an unknown quantity at this point
XML generation - Incomplete XML

Alright so I'm trying to generate an XML file by reading a text document.
I've done this successfully up to a point, but my XML is not generating the video, audio, and document elements that I've tried to create.

The basic format of my xml is as follows:
<Scrapbook>
<pages>
<page>
<keyframe>
<textbody>
<picture>
<video>
<audio>
<document>
</keyframe>
</page>
</pages>
</Scrapbook>

where there can be multiple page tags per pages tag and multiple keyframe tags per page tag. There can also be multiple textbody, picture, video, audio, and document tags per keyframe.

In my test textfile, I've got 1 page with 1 keyframe that holds 2 textbodies, 1 picture, 1 video, 1 audio, and 1 document.
The problem is that my php doesn't get the video, audio and document tag in the XML it generates.

I've eliminated the possibility that the text document that I provide is wrong.
So there has to be something different between how I'm adding the textbody and picture tags versus the the tags that don't make it.

I've searched my code up and down and I can't find it what I'm doing wrong.


Here's my code:

PHP Code:
<?php

//get the contents of the file generated from the editor
$myfile file_get_contents("test.txt");


$array split("\n",$myfile);
print_r($array);

//then convert into our xml format.
$doc = new DOMDocument();
$doc->formatOutput true;

//Scrapbook
$Scrapbook $doc->createElement("Scrapbook");
//$doc->appendChild($Scrapbook);
//required scrapbook attributes:

//Scrapbook Attributes....

$pages $doc->createElement("pages");
//$doc->appendChild($pages);

$numberofpages array_shift($array);

for(
$i=0$i<$numberofpages$i++){

    
$page $doc->createElement("page");
    
    
//required page attributes:
    
...    
    
    
$numberofkeyframes array_shift($array);
    for(
$k=0$k<$numberofkeyframes$k++){
        
        
$keyframe $doc->createElement("keyframe");
    
        
$keyframe_id array_shift($array);
        
$keyframe_time array_shift($array);
        
$keyframe_type array_shift($array);
        
        
//id
        
$keyframe_attr_id $doc->createAttribute("id");
        
$keyframe->appendChild$keyframe_attr_id );
        
$keyframe_id_value $doc->createTextNode($keyframe_id);
        
$keyframe_attr_id->appendChild($keyframe_id_value);
        
        
//time
        
$keyframe_attr_time $doc->createAttribute("time");
        
$keyframe->appendChild$keyframe_attr_time );
        
$keyframe_time_value $doc->createTextNode($keyframe_time);
        
$keyframe_attr_time->appendChild($keyframe_time_value);
    
        
//type
        
$keyframe_attr_type $doc->createAttribute("type");
        
$keyframe->appendChild$keyframe_attr_type );
        
$keyframe_type_value $doc->createTextNode($keyframe_type);
        
$keyframe_attr_type->appendChild($keyframe_type_value);
        
        
$numberoftextbodies array_shift($array);
        for(
$j=0$j<$numberoftextbodies$j++){
            
$textbody_id array_shift($array);
            
$textbody_x array_shift($array);
            
$textbody_y array_shift($array);
            
$textbody_z array_shift($array);
            
$textbody_w array_shift($array);
            
$textbody_h array_shift($array);
            
$textbody_text array_shift($array);
            
$textbody_fontcolor array_shift($array);
            
$textbody_fontsize array_shift($array);
            
$textbody_fontfamily array_shift($array);
            
$textbody_color array_shift($array);
            
            
//textbody
            
$textbody $doc->createElement("textbody");
            
$textbody->appendChild$doc->createTextNode($textbody_text) );
            
//$textbody->appendChild( $doc->createTextNode($page[$textbody_text])); //FLAG
        
            //id
            
$textbody_attr_id $doc->createAttribute("id");
            
$textbody->appendChild$textbody_attr_id );
            
$textbody_id_value $doc->createTextNode($textbody_id);
            
$textbody_attr_id->appendChild($textbody_id_value);
            
            
//xloc
            
$textbody_attr_xloc $doc->createAttribute("xloc");
            
$textbody->appendChild$textbody_attr_xloc );
            
$textbody_xloc_value $doc->createTextNode($textbody_x);
            
$textbody_attr_xloc->appendChild($textbody_xloc_value);
            
            
//yloc
            
$textbody_attr_yloc $doc->createAttribute("yloc");
            
$textbody->appendChild$textbody_attr_yloc );
            
$textbody_yloc_value $doc->createTextNode($textbody_y);
            
$textbody_attr_yloc->appendChild($textbody_yloc_value);
            
            
//zloc
            
$textbody_attr_zloc $doc->createAttribute("zloc");
            
$textbody->appendChild$textbody_attr_zloc );
            
$textbody_zloc_value $doc->createTextNode($textbody_z);
            
$textbody_attr_zloc->appendChild($textbody_zloc_value);
            
            
//width
            
$textbody_attr_width $doc->createAttribute("width");
            
$textbody->appendChild$textbody_attr_width );
            
$textbody_width_value $doc->createTextNode($textbody_w);
            
$textbody_attr_width->appendChild($textbody_width_value);
            
            
//height
            
$textbody_attr_height $doc->createAttribute("height");
            
$textbody->appendChild$textbody_attr_height );
            
$textbody_height_value $doc->createTextNode($textbody_h);
            
$textbody_attr_height->appendChild($textbody_height_value);
            
            
//fontcolor - default: "black"
            
$textbody_attr_fontcolor $doc->createAttribute("fontcolor");
            
$textbody->appendChild$textbody_attr_fontcolor );
            
$textbody_fontcolor_value $doc->createTextNode($textbody_fontcolor);
            
$textbody_attr_fontcolor->appendChild($textbody_fontcolor_value); 
        
            
//fontsize - default: "12"
            
$textbody_attr_fontsize $doc->createAttribute("fontsize");
            
$textbody->appendChild$textbody_attr_fontsize );
            
$textbody_fontsize_value $doc->createTextNode($textbody_fontsize);
            
$textbody_attr_fontsize->appendChild($textbody_fontsize_value);
            
            
//fontfamily - default: "Times New Roman"
            
$textbody_attr_fontfamily $doc->createAttribute("fontfamily");
            
$textbody->appendChild$textbody_attr_fontfamily );
            
$textbody_fontfamily_value $doc->createTextNode($textbody_fontfamily);
            
$textbody_attr_fontfamily->appendChild($textbody_fontfamily_value);
            
            
//color - default: "white"
            
$textbody_attr_color $doc->createAttribute("color");
            
$textbody->appendChild$textbody_attr_color );
            
$textbody_color_value $doc->createTextNode($textbody_color);
            
$textbody_attr_color->appendChild($textbody_color_value);
            
            
            
//append the whole textbody with attributes
            
$keyframe->appendChild($textbody);
        }
        
$numberofpictures array_shift($array);
        for(
$j=0$j<$numberofpictures$j++){
            
$picture_id array_shift($array);
            
$picture_x array_shift($array);
            
$picture_y array_shift($array);
            
$picture_z array_shift($array);
            
$picture_w array_shift($array);
            
$picture_h array_shift($array);
            
$picture_storage array_shift($array);
            
$picture_link array_shift($array);
            
$picture_rotation array_shift($array);
            
            
//picture
            
$picture $doc->createElement("picture");
            
$picture->appendChild$doc->createTextNode($picture_storage) );
            
//$picture->appendChild( $doc->createTextNode($page["picture1"/*$picture_storage*/])); //FLAG - what goes in between the tags? $picture_storage?
        
            //id
            
$picture_attr_id $doc->createAttribute("id");
            
$picture->appendChild$picture_attr_id );
            
$picture_id_value $doc->createTextNode($picture_id);
            
$picture_attr_id->appendChild($picture_id_value);
            
            
//xloc
            
$picture_attr_xloc $doc->createAttribute("xloc");
            
$picture->appendChild$picture_attr_xloc );
            
$picture_xloc_value $doc->createTextNode($picture_x);
            
$picture_attr_xloc->appendChild($picture_xloc_value);
            
            
//yloc
            
$picture_attr_yloc $doc->createAttribute("yloc");
            
$picture->appendChild$picture_attr_yloc );
            
$picture_yloc_value $doc->createTextNode($picture_y);
            
$picture_attr_yloc->appendChild($picture_yloc_value);
            
            
//zloc
            
$picture_attr_zloc $doc->createAttribute("zloc");
            
$picture->appendChild$picture_attr_zloc );
            
$picture_zloc_value $doc->createTextNode($picture_z);
            
$picture_attr_zloc->appendChild($picture_zloc_value);
            
            
//width
            
$picture_attr_width $doc->createAttribute("width");
            
$picture->appendChild$picture_attr_width );
            
$picture_width_value $doc->createTextNode($picture_w);
            
$picture_attr_width->appendChild($picture_width_value);
            
            
//height
            
$picture_attr_height $doc->createAttribute("height");
            
$picture->appendChild$picture_attr_height );
            
$picture_height_value $doc->createTextNode($picture_h);
            
$picture_attr_height->appendChild($picture_height_value);
            
            
//storage - FLAG - storage value may be inbetween tags
            
$picture_attr_storage $doc->createAttribute("storage");
            
$picture->appendChild$picture_attr_storage );
            
$picture_storage_value $doc->createTextNode($picture_storage);
            
$picture_attr_storage->appendChild($picture_storage_value);
            
            
//link
            
$picture_attr_link $doc->createAttribute("link");
            
$picture->appendChild$picture_attr_link );
            
$picture_link_value $doc->createTextNode($picture_link);
            
$picture_attr_link->appendChild($picture_link_value);
            
            
//rotation
            
$picture_attr_rotation $doc->createAttribute("rotation");
            
$picture->appendChild$picture_attr_rotation );
            
$picture_rotation_value $doc->createtextNode($picture_rotation);
            
$picture_attr_rotation->appendChild($picture_rotation_value);
            
            
//append the whole picture with attributes
            
$keyframe->appendChild($picture);
        }
        
$numberofvideos array_shift($array);
        for(
$j=0$j<numberofvideos$j++){
            
$video_id array_shift($array);
            
$video_xloc array_shift($array);
            
$video_yloc array_shift($array);
            
$video_zloc array_shift($array);
            
$video_width array_shift($array);
            
$video_height array_shift($array);
            
$video_type array_shift($array);
            
$video_link array_shift($array);
            
            
//video
            
$video $doc->createElement("video");
            
$video->appendChild$doc->createTextNode($video_link) );
            
//$video->appendChild( $doc->createTextNode($page["video1"/*$video_storage*/])); //FLAG - what goes in between the tags? $video_storage?
        
            //id
            
$video_attr_id $doc->createAttribute("id");
            
$video->appendChild$video_attr_id );
            
$video_id_value $doc->createTextNode($video_id);
            
$video_attr_id->appendChild($video_id_value);
            
//xloc
            
$video_attr_xloc $doc->createAttribute("xloc");
            
$video->appendChild$video_attr_xloc );
            
$video_xloc_value $doc->createTextNode($video_xloc);
            
$video_attr_xloc->appendChild($video_xloc_value);
            
//yloc
            
$video_attr_yloc $doc->createAttribute("yloc");
            
$video->appendChild$video_attr_yloc );
            
$video_yloc_value $doc->createTextNode($video_yloc);
            
$video_attr_yloc->appendChild($video_yloc_value);
            
//zloc
            
$video_attr_zloc $doc->createAttribute("zloc");
            
$video->appendChild$video_attr_zloc );
            
$video_zloc_value $doc->createTextNode($video_zloc);
            
$video_attr_zloc->appendChild($video_zloc_value);
            
//width
            
$video_attr_width $doc->createAttribute("width");
            
$video->appendChild$video_attr_width );
            
$video_width_value $doc->createTextNode($video_width);
            
$video_attr_width->appendChild($video_width_value);
            
//height
            
$video_attr_height $doc->createAttribute("height");
            
$video->appendChild$video_attr_height );
            
$video_height_value $doc->createTextNode($video_height);
            
$video_attr_height->appendChild($video_height_value);
            
//type
            
$video_attr_type $doc->createAttribute("type");
            
$video->appendChild$video_attr_type );
            
$video_type_value $doc->createTextNode($video_type);
            
$video_attr_type->appendChild($video_type_value);
            
//link
            
$video_attr_link $doc->createAttribute("link");
            
$video->appendChild$video_attr_link );
            
$video_link_value $doc->createTextNode($video_link);
            
$video_attr_link->appendChild($video_link_value);
            
            
$keyframe->appendChild($video);
        }
        
$numberofaudio array_shift($array);
        for(
$j=0$j<numberofaudio$j++){
            
$audio_id array_shift($array);
            
$audio_loopmode array_shift($array);
            
$audio_xloc array_shift($array);
            
$audio_yloc array_shift($array);
            
$audio_zloc array_shift($array);
            
$audio_link array_shift($array);
            
$audio_playmode array_shift($array);
            
            
//audio
            
$audio $doc->createElement("audio");
            
$audio->appendChild$doc->createTextNode($audio_link) );
            
//$audio->appendChild( $doc->createTextNode($page["audio1"/*$audio_storage*/])); //FLAG - what goes in between the tags? $audio_storage?
        
            //id
            
$audio_attr_id $doc->createAttribute("id");
            
$audio->appendChild$audio_attr_id );
            
$audio_id_value $doc->createTextNode($audio_id);
            
$audio_attr_id->appendChild($audio_id_value);
            
//loopmode
            
$audio_attr_loopmode $doc->createAttribute("loopmode");
            
$audio->appendChild$audio_attr_loopmode );
            
$audio_loopmode_value $doc->createTextNode($audio_loopmode);
            
$audio_attr_loopmode->appendChild($audio_loopmode_value);
            
//xloc
            
$audio_attr_xloc $doc->createAttribute("xloc");
            
$audio->appendChild$audio_attr_xloc );
            
$audio_xloc_value $doc->createTextNode($audio_xloc);
            
$audio_attr_xloc->appendChild($audio_xloc_value);
            
//yloc
            
$audio_attr_yloc $doc->createAttribute("yloc");
            
$audio->appendChild$audio_attr_yloc );
            
$audio_yloc_value $doc->createTextNode($audio_yloc);
            
$audio_attr_yloc->appendChild($audio_yloc_value);
            
//zloc
            
$audio_attr_zloc $doc->createAttribute("zloc");
            
$audio->appendChild$audio_attr_zloc );
            
$audio_zloc_value $doc->createTextNode($audio_zloc);
            
$audio_attr_zloc->appendChild($audio_zloc_value);
            
//link
            
$audio_attr_link $doc->createAttribute("link");
            
$audio->appendChild$audio_attr_link );
            
$audio_link_value $doc->createTextNode($audio_link);
            
$audio_attr_link->appendChild($audio_link_value);
            
//playmode
            
$audio_attr_playmode $doc->createAttribute("playmode");
            
$audio->appendChild$audio_attr_playmode );
            
$audio_playmode_value $doc->createTextNode($audio_playmode);
            
$audio_attr_playmode->appendChild($audio_playmode_value);
            
            
$keyframe->appendChild($audio);
        }
        
$numberofdocuments array_shift($array);
        for(
$j=0$j<numberofdocuments$j++){
            
$document_id array_shift($array);
            
$document_xloc array_shift($array);
            
$document_yloc array_shift($array);
            
$document_zloc array_shift($array);
            
$document_width array_shift($array);
            
$document_height array_shift($array);
            
$document_type array_shift($array);
            
$document_link array_shift($array);
            
$document_linktype array_shift($array);
            
            
//document
            
$document $doc->createElement("document");
            
$document->appendChild$doc->createTextNode($document_link) );
            
//$document->appendChild( $doc->createTextNode($page["document1"/*$document_storage*/])); //FLAG - what goes in between the tags? $document_storage?
        
            //id
            
$document_attr_id $doc->createAttribute("id");
            
$document->appendChild$document_attr_id );
            
$document_id_value $doc->createTextNode($document_id);
            
$document_attr_id->appendChild($document_id_value);
            
//xloc
            
$document_attr_xloc $doc->createAttribute("xloc");
            
$document->appendChild$document_attr_xloc );
            
$document_xloc_value $doc->createTextNode($document_xloc);
            
$document_attr_xloc->appendChild($document_xloc_value);
            
//yloc
            
$document_attr_yloc $doc->createAttribute("yloc");
            
$document->appendChild$document_attr_yloc );
            
$document_yloc_value $doc->createTextNode($document_yloc);
            
$document_attr_yloc->appendChild($document_yloc_value);
            
//zloc
            
$document_attr_zloc $doc->createAttribute("zloc");
            
$document->appendChild$document_attr_zloc );
            
$document_zloc_value $doc->createTextNode($document_zloc);
            
$document_attr_zloc->appendChild($document_zloc_value);
            
//width
            
$document_attr_width $doc->createAttribute("width");
            
$document->appendChild$document_attr_width );
            
$document_width_value $doc->createTextNode($document_width);
            
$document_attr_width->appendChild($document_width_value);
            
//height
            
$document_attr_height $doc->createAttribute("height");
            
$document->appendChild$document_attr_height );
            
$document_height_value $doc->createTextNode($document_height);
            
$document_attr_height->appendChild($document_height_value);
            
//type
            
$document_attr_type $doc->createAttribute("type");
            
$document->appendChild$document_attr_type );
            
$document_type_value $doc->createTextNode($document_type);
            
$document_attr_type->appendChild($document_type_value);
            
//link
            
$document_attr_link $doc->createAttribute("link");
            
$document->appendChild$document_attr_link );
            
$document_link_value $doc->createTextNode($document_link);
            
$document_attr_link->appendChild($document_link_value);
            
//linktype
            
$document_attr_linktype $doc->createAttribute("linktype");
            
$document->appendChild$document_attr_linktype );
            
$document_linktype_value $doc->createTextNode($document_linktype);
            
$document_attr_linktype->appendChild($document_linktype_value);
            
            
$keyframe->appendChild($document);
        }
        
$page->appendChild($keyframe);
    }
    
$pages->appendChild($page);
}
$Scrapbook->appendChild($pages);

$doc->appendChild($Scrapbook);

//echo $doc->saveXML();

/*
$dtd = "http://www.uisource.com/RossCode/xmltest/Scrapbookv5.dtd"; 


if($doc->validate()){
    echo "This document is valid!\n";
    $doc->save("ScrapbookTest.xml");
} else { 
    echo "this document is not valid!\n"; 
}*/

$doc->save("ScrapbookTest2.xml");

//header('Content-Type: text/xml');
//header('Content-Disposition: attachment; filename="example.xml"');
//header('content-Transfer-Encoding: binary');


?>
here's what actually gets generated:

Any help would be greatly appreciated.
tensai is offline   Reply With Quote
Old 12-07-2009, 08:59 PM   PM User | #2
tensai
New to the CF scene

 
Join Date: Dec 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
tensai is an unknown quantity at this point
Here's what actually gets generated:

Code:
<?xml version="1.0"?>
<Scrapbook name="Tyrannosaurus Scrapbook" sizex="1024" sizey="700" compatibilitymode="mostbrowsers" theme="Tyrannosaurus Rex" transitionmethod="click">
  <pages>
    <page id="1" ordernumber="1" backgroundcolor="red" backgroundimage="none" transitionmethod="click" transitiontime="2" transitioneffect="fade">
      <keyframe id="1" time="0" type="normal">
        <textbody id="11" xloc="100" yloc="50" zloc="1" width="50" height="50" fontcolor="black" fontsize="12" fontfamily="Arial" color="white">Tyrannosaurus Scrapbook</textbody>
        <textbody id="12" xloc="100" yloc="125" zloc="2" width="50" height="50" fontcolor="black" fontsize="12" fontfamily="Arial" color="white">2009</textbody>
        <picture id="13" xloc="50" yloc="50" zloc="3" width="50" height="50" storage="Flikr" link="http://thisisyourpicture.com/pic1.bmp" rotation="3">Flikr</picture>
      </keyframe>
    </page>
  </pages>
</Scrapbook>
tensai is offline   Reply With Quote
Reply

Bookmarks

Tags
appendchild(), create, createtextnode(), php, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:05 PM.


Advertisement
Log in to turn off these ads.