SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Header content type for XML

    Hi guys!

    i am using a php script to collect data from my database and hopefully produce a sitemap in xml format that i would submit to google. at the end of the script, im using this code before i echo the text.

    header("Content-type: text/xml");

    With firefox, IE and netscape, the xml is displayed just fine, but on opera, it displays them as plain text.

    whats the problem here? or am i using a non-standard content type value here?
    If you won't dress like the
    Victoria Secret girls,
    don't expect us to act like soap opera guys.

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is weird but some browsers decide the mime-type of a file via file extensions instead of 'Content-type' header. I doubt this is the case with Opera but does you file has PHP extension?

  3. #3
    SitePoint Enthusiast mithra62's Avatar
    Join Date
    Nov 2004
    Location
    Van Nuys
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    doctype maybe

    Have you thought about echoing out an XML doctype? I don't know for sure if that would work but it makes sense to me; as long as the echo was after all the header() calls obviously.

  4. #4
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will second this. Check your doctype.

  5. #5
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im using the template google suggest in their site..

    <?xml version="1.0" encoding="UTF-8"?>
    If you won't dress like the
    Victoria Secret girls,
    don't expect us to act like soap opera guys.

  6. #6
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kailash Badu View Post
    This is weird but some browsers decide the mime-type of a file via file extensions instead of 'Content-type' header. I doubt this is the case with Opera but does you file has PHP extension?
    yes, this is what appears on the addressbar: http://localhost/someproject/generate_sitemap.php

    does it ring a bell? hope you guys sees whats wrong..

    also on XML, "&" is an invalid character...i replaced it with "&amp;". When i submit my xml file to google, will this not return any error?
    If you won't dress like the
    Victoria Secret girls,
    don't expect us to act like soap opera guys.

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Browsers should accept the content type the server sends as the content type of the document. If Firefox, IE and Netscape all accept the file, it's working fine don't worry about it - Opera behaves a little differently. Either way, google will still be able to read your XML, and Opera users won't be opening the raw XML data anyway.

  8. #8
    SitePoint Evangelist lance_vincent's Avatar
    Join Date
    Aug 2004
    Location
    philippines
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Akash Mehta View Post
    Browsers should accept the content type the server sends as the content type of the document. If Firefox, IE and Netscape all accept the file, it's working fine don't worry about it - Opera behaves a little differently. Either way, google will still be able to read your XML, and Opera users won't be opening the raw XML data anyway.
    thanks! yeah i really dont mind really if opera can open the xml in the browser. i have submitted my sitemap.xml yippee! but then, it just bugs me why oepra wont display it..im a programmer so i thought id ask.. i dont want customers asking but then i cant explain..
    If you won't dress like the
    Victoria Secret girls,
    don't expect us to act like soap opera guys.

  9. #9
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Opera doesn't display formatted xml for some reason.

  10. #10
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondering why anyone would open it anyway. XML site maps aren't really for viewing, just for Google to download and if it's in their format it's just fine.

  11. #11
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... maybe you'd want to see if you formatted it right?

    Quote Originally Posted by devbanana View Post
    Just wondering why anyone would open it anyway. XML site maps aren't really for viewing, just for Google to download and if it's in their format it's just fine.

  12. #12
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but, it's not like people should be opening it that often, especially site visitors. It's kinda a backend thing that people don't even need to know about.

  13. #13
    SitePoint Zealot
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    137
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    devbanana has a good point. The whole point of non-text based web browsers (die, Lynx, die! :P) is being able to present content. The whole point of XML is being able to seperate content from presentation. (Alternatively, the whole point of HTML is to add presentation to content...) So you can fetch data from your XML file but before a site visitor views it, it should be formatted, prettified and all the rest. (This is where XSLT complicates the issue.) You should probably rewrite requests to your XML file from a web browser, sending them to a formatted version of the content of the XML file (if only to a generic php script that fetches and parses the XML, then displays it in a tree view or similar).


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
  •