#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,657
    Rep Power
    171

    Generating xml from database


    Hello;

    I want to generate an xml for someone who is making an iphone ap. He wants xml. As I have never done this before, I wonder if this is o right or not? It works fine but I need to confirm. Outputs this

    Thanks

    PHP Code:
    <?php  include "includes.php";
    $sql "SELECT * FROM systematic_attraction_sub_categories WHERE status=:status ";
    $args_sub = array('status'=>'active');
    $data DB::Load()->Execute($sql$args_sub)->returnArray();

    foreach(
    $data as $val=>$row)
        {
            
    $My_videoss[] = new My_videos($row['title'], $row['description'], $row['price'], $row['thumbnail'], $row['youtube_link']);   
        }
    class 
    My_videos
        
    {
            public 
    $title;
            public 
    $description;
            public 
    $price;
            public 
    $thumbnail_url;
            public 
    $youtube_embed;
            
            function 
    __construct($title$description$price$thumbnail_url$youtube_embed)
                {
                    
    $this->title $title;
                    
    $this->description $description;
                    
    $this->price $price;
                    
    $this->thumbnail_url $thumbnail_url;
                    
    $this->youtube_embed $youtube_embed;
                }
        }

    $xmlDoc = new DOMDocument();
    $root $xmlDoc->appendChild(
    $xmlDoc->createElement("videos"));
           

    foreach(
    $My_videoss as $tut)
        {
        
            
    $tutTag $root->appendChild(
            
    $xmlDoc->createElement("video"));

            
    $tutTag->appendChild(
            
    $xmlDoc->createElement("Title"$tut->title));
            
            
    $tutTag->appendChild(
            
    $xmlDoc->createElement("Description"$tut->description));
            
            
    $tutTag->appendChild(
            
    $xmlDoc->createElement("Price"$tut->price));
            
            
    $tutTag->appendChild(
            
    $xmlDoc->createElement("thumbnail_url"$tut->thumbnail_url));
            
            
    $tutTag->appendChild(
            
    $xmlDoc->createElement("video_url"$tut->youtube_embed));
            
         }

    header ("Content-Type:text/xml"); 
    $xmlDoc->formatOutput true;
    echo 
    $file $xmlDoc->saveXML();
  2. #2
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    It outputs valid xml, so you're done?

    Maybe

    It depends what your developer wants, does it contain all the information he wants?

    Does he want it namespacing?

    Does he want to validate the xml against a schema (xsd file)?
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #3
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,657
    Rep Power
    171
    Originally Posted by Northie
    It outputs valid xml, so you're done?

    Maybe

    It depends what your developer wants, does it contain all the information he wants?

    Does he want it namespacing?

    Does he want to validate the xml against a schema (xsd file)?
    The test version of the ap is working fine on iphone. I was just checking the way I am making the xml. Sometimes make things that work but they are not the best practice.

IMN logo majestic logo threadwatch logo seochat tools logo