Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem in conversion of XML

    hi,

    i run the below code i got the following error and also display output normal way instead of xml entries.plz help that what's the mistake in my code


    PHP Code:

     <?
    header
    ("Content-type: text/xml");
    $host "localhost";
    $user "root";
    $pass "root";
    $database "DataMiningdb";

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host.");
    mysql_select_db($database$linkID) or die("Could not find database.");

    $query "SELECT * FROM vehicles ORDER BY vehicle_id DESC";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<entries>\n";

    for(
    $x $x mysql_num_rows($resultID) ; $x++){
        
    $row mysql_fetch_assoc($resultID);
        
    $xml_output .= "\t<entry>\n";
        
    $xml_output .= "\t\t<vehicle_id>" $row['vehicle_id'] . "</vehicle_id>\n";
            
    // Escaping illegal characters
            
    $row['vehicle_make'] = str_replace("&""&"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace("<""<"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace(">""&gt;"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace("\"""&quot;"$row['vehicle_make']);
        
    $xml_output .= "\t\t<vehicle_make>" $row['vehicle_make'] . "</vehicle_make>\n";
        
    $xml_output .= "\t</entry>\n";
    }

    $xml_output .= "</entries>";
    echo 
    $xml_output;

    ?>

    output:


    Warning: Cannot modify header information - headers already sent by (output started at F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php:1) in F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php on line 2
    5 Bayliner 5 Bayliner 5 Bayliner 4 Bayliner 4 Bayliner 4 Bayliner 3 Baja Marine 3 Baja Marine 3 Baja Marine 2 Miscellaneous 2 Miscellaneous 2 Miscellaneous 1 Miscellaneous 1 Miscellaneous 1 Miscellaneous

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    At the top you have a space before the tag, for it to work there must be nothing at all... also <? is disappreciated. use <?php

    e.g.
    PHP Code:
    <?php

    header
    ("Content-type: text/xml");
    $host "localhost";
    $user "root";
    $pass "root";
    $database "DataMiningdb";

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host.");
    mysql_select_db($database$linkID) or die("Could not find database.");

    $query "SELECT * FROM vehicles ORDER BY vehicle_id DESC";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<entries>\n";

    for(
    $x $x mysql_num_rows($resultID) ; $x++){
        
    $row mysql_fetch_assoc($resultID);
        
    $xml_output .= "\t<entry>\n";
        
    $xml_output .= "\t\t<vehicle_id>" $row['vehicle_id'] . "</vehicle_id>\n";
            
    // Escaping illegal characters
            
    $row['vehicle_make'] = str_replace("&""&"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace("<""<"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace(">""&gt;"$row['vehicle_make']);
            
    $row['vehicle_make'] = str_replace("\"""&quot;"$row['vehicle_make']);
        
    $xml_output .= "\t\t<vehicle_make>" $row['vehicle_make'] . "</vehicle_make>\n";
        
    $xml_output .= "\t</entry>\n";
    }

    $xml_output .= "</entries>";
    echo 
    $xml_output;

    ?>

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    <?php
    header
    ("Content-type: text/xml");
    $host "localhost";
    $user "root";
    $pass "root";
    $database "DataMiningdb";

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host.");
    mysql_select_db($database$linkID) or die("Could not find database.");

    $query "SELECT * FROM vehicles ORDER BY vehicle_id DESC";
    $resultID mysql_query($query$linkID) or die("Data not found.");

    $xml_output "<?xml version=\"1.0\"?>\n";
    $xml_output .= "<entries>\n";

    for(
    $x $x mysql_num_rows($resultID) ; $x++){
        
    $row mysql_fetch_assoc($resultID);
        
    $xml_output .= "\t<entry>\n";
        
    $xml_output .= "\t\t<vehicle_id>" $row['vehicle_id'] . "</vehicle_id>\n";
            
    // Escaping illegal characters
            
    $row['vehicle_make'] = htmlspecialchars($row['vehicle_make']);
        
    $xml_output .= "\t</entry>\n";
    }

    $xml_output .= "</entries>";
    echo 
    $xml_output;

    ?>
    regards


  •  

    Posting Permissions

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