dynamically create sitemap xml using php

Discussion in 'PHP' started by rekha, Jun 15, 2010.

  1. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have created sitemap for my site using some reference code in the below link

    http://stackoverflow.com/questions/2...temap-with-php

    But I am getting error as

    XML Parsing Error: undefined entity Location:

    as my content is as follows

    << alt >> attribute and it says something like

    < loc >http://www.example.com/700- & laquo;alt & raquo;-attributes-in-images.php< /loc >

    Can anyone tell me how to get rid of this error.
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    Could you please post your code here?
     
  3. rekha

    rekha New Member

    Joined:
    Jan 17, 2008
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I tried another code I have given below.It works fine but the encoding is the problem here.

    I got the following error,

    Code:
    An invalid character was found in text content. Error processing resource
    when I dynamically created xml file using php.The encoding I used was utf-8.I changed it to ISO-8859-1.The error resolved.But the issue is I am having tamil,hindi content So it is displayed as

    Code:
    à®à®à¯à®°à®¾-à®à¯à®à¯à®à¯-
    Code:
    header('Content-Type: application/xml'); echo '<?xml version="1.0" encoding="UTF-8"?>'."\n"; ?> <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"> <?php $sql = "SELECT * FROM table "; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?>  <url>  <loc>http://example.com/<?php echo $row[2]; ?></loc>  <lastmod><?php echo str_replace(' ', 'T', $row['dat']).substr(date("O"), 0, -2).':00'; ?></lastmod>  </url> <?php } ?></urlset>
    How to solve this?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice