Close

Results 1 to 9 of 9

Thread: PHP->XML help

  1. #1
    DF VIP Member ParkerDigital's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    455
    Thanks
    0
    Thanked:        0
    Karma Level
    239

    Help PHP->XML help

    I'm using a PHP script to pull data from a MySQL database, and then output it as XML in order to send it to a Flash movie. It's a script I've used before without any problems, but this time I must have done something wrong somewhere, as when I test it in IE I get a message saying "The XML page cannot be displayed". Here's the code:

    Code:
            print '<?xml version="1.0"?>
        <!DOCTYPE jobads[
        <!ELEMENT jobads (jobad)>
        <!ELEMENT jobad (id, jobtitle, salary, location)>
        <!ELEMENT id (#PCDATA)>
        <!ELEMENT jobtitle (#PCDATA)>
        <!ELEMENT salary (#PCDATA)>
        <!ELEMENT location (#PCDATA)>
        ]>
    
    <jobads>';
            
            while ( $r1 = mysql_fetch_array($q) ) {
                print '<jobad>';
                print '<id>'.$r1['id'].'</id>';
                print '<jobtitle>'.$r1['jobTitle'].'</jobtitle>';
                print '<salary>'.$r1['salary'].'</salary>';
                print '<location>'.$r1['location'].'</location>';
                print '</jobad>';
                }
            
            print '</jobads>';
    I've left out the SQL code as I know that there's no problem in getting the data from the database. I'm guessing that the problem is with the XML output. Anyone have any ideas?

  2. #2
    DF VIP Member partyman's Avatar
    Join Date
    Jul 2001
    Location
    Saarf Larndarn
    Posts
    1,398
    Thanks
    0
    Thanked:        0
    Karma Level
    436

    Default Re: PHP->XML help

    What does firefox say when try to view it? Can you view what it's outputting? (ie the raw code)

  3. #3
    DF VIP Member ParkerDigital's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    455
    Thanks
    0
    Thanked:        0
    Karma Level
    239

    Default Re: PHP->XML help

    partyman, In Firefox it's displayed like this

    Code:
    ]> 10Marketing Assistant£16,000Mold, North Wales8Accounts Manager£22,000Ormskirk7Web Designer£18,000Ormskirk9Airline Pilot£45,000Manchester11Treasurer£28,000Birmingham
    ...which is essentially the data from the database, with the last bracket from the XML DTD at the beginning. In the past I've had similar scripts that displayed in a similar way in Firefox, and worked fine when I parsed them in Flash. It's just that normally they display OK in IE and don't give me any error messages.

  4. #4
    DF VIP Member partyman's Avatar
    Join Date
    Jul 2001
    Location
    Saarf Larndarn
    Posts
    1,398
    Thanks
    0
    Thanked:        0
    Karma Level
    436

    Default Re: PHP->XML help

    You may need to put in:
    Code:
    header('Content-Type: text/xml');

  5. #5
    DF VIP Member ParkerDigital's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    455
    Thanks
    0
    Thanked:        0
    Karma Level
    239

    Default Re: PHP->XML help

    Quote Originally Posted by partyman View Post
    You may need to put in:
    Code:
    header('Content-Type: text/xml');
    Great - that works fine in Firefox now. Still get the error code in IE, but if Firefox says it's OK, that's good enough for me!

    Cheers

  6. #6
    DF VIP Member hxbro's Avatar
    Join Date
    Nov 2000
    Location
    Behind a wall
    Posts
    2,731
    Thanks
    4
    Thanked:        18
    Karma Level
    476

    Default Re: PHP->XML help

    for one of my flash things I use the following:

    PHP Code:
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
    echo 
    "<screenshots>\n";
    while (
    $row mysql_fetch_array($result))
    {
    ?>
        <screenshot caption="<?php echo rawurlencode($row['description'] . "<br><br>Click for more information"?>" productid="<?php echo $row['product_id'?>" id="<?php echo $row['id'?>" />
    <?
    }
    ?>
    </screenshots>
    try remove the doctype.

    Also in flash dont forget to tell it to ignore the white space by doing

    xmlDoc.ignoreWhite = true;
    Download my latest breaks and electro mixes or listen to Sellout Breaks FM

  7. #7
    DF VIP Member hxbro's Avatar
    Join Date
    Nov 2000
    Location
    Behind a wall
    Posts
    2,731
    Thanks
    4
    Thanked:        18
    Karma Level
    476

    Default Re: PHP->XML help

    also make sure things are proper html e.g. £ shouldn't be £, try htmlspecialchars($r1['salary'])
    Download my latest breaks and electro mixes or listen to Sellout Breaks FM

  8. #8
    DF VIP Member ParkerDigital's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    455
    Thanks
    0
    Thanked:        0
    Karma Level
    239

    Default Re: PHP->XML help

    Quote Originally Posted by hxbro View Post
    also make sure things are proper html e.g. £ shouldn't be £, try htmlspecialchars($r1['salary'])
    Thanks for that. Oh, and the whitespace thing. I had to find out about that one the hard way - hours and hours of wondering why my trace command was bringing up "undefined" for my parsed data

  9. #9
    DF VIP Member hxbro's Avatar
    Join Date
    Nov 2000
    Location
    Behind a wall
    Posts
    2,731
    Thanks
    4
    Thanked:        18
    Karma Level
    476

    Default Re: PHP->XML help

    got me too, spent a week wondering why it didn't work
    Download my latest breaks and electro mixes or listen to Sellout Breaks FM

Social Networking 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
  •