SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Writing an XML file, am I missing something?

    Hi All,

    This is my first foray into XML. I need to write an XML file which can later be uses with a flash app. Now, I found the code below from a tut and tried to modify it for my needs :

    Code:
    <?php
    
    // retrieve all vehicles from DB
    $query = "SELECT * FROM vehicles";
    $dbresult = $database->executeQuery($query, $dbLink);
    
    $table_id="vehicles";
    
    $doc = domxml_new_doc('1.0');
    
    // create root node
    $root = $doc->create_element('root');
    $root = $doc->append_child($root);
    
    // process one row at a time
    while($row = mysql_fetch_assoc($dbresult)) {
    
        // add node for each row
        $occ = $doc->create_element($table_id);
        $occ = $root->append_child($occ);
        
        // add a child node for each field
        foreach ($row as $fieldname => $fieldvalue) {
        
            $child = $doc->create_element($fieldname);
               $child = $occ->append_child($child);
            
            } // foreach
    } // while
    
    // get completed xml document
    $xml_string = $doc->dump_mem(true);
    
    echo $xml_string;
    Now I connect to the DB (not shown) and retrieve all vehicle records. This seems to work but when I look at the XML in FF I see this:

    <root>
    <vehicles>
    <vehicleID/>
    <make/>
    <model/>
    <registered/>
    <milage/>
    <colour/>And so on...

    The structure looks good but where's the DB info i.e. vehicle info? I'm sooo green with this I'd be very grateful of any guidance.

    Rob

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    London, England
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // add a child node for each field
    foreach ($row as $fieldname => $fieldvalue) {
        
    $child $doc->create_element($fieldname$fieldvalue);
        
    $child $occ->append_child($child);
    // foreach 
    Edit: Sorry I was thinking of DOMDocument->createElement()


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •