Bug #63853 [Opn->Fbk]: Some of the urls are not added in $url->addchild("loc",$mainurl);

From: Date: Mon, 02 Dec 2013 16:32:08 +0000
Subject: Bug #63853 [Opn->Fbk]: Some of the urls are not added in $url->addchild("loc",$mainurl);
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183071@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63853&edit=1

 ID:                 63853
 Updated by:         mike@php.net
 Reported by:        sachinpkaushik at gmail dot com
 Summary:            Some of the urls are not added in
                     $url->addchild("loc",$mainurl);
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            DOM XML related
 Operating System:   Fedora Linux
 PHP Version:        5.4.10
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.




Previous Comments:
------------------------------------------------------------------------
[2012-12-31 22:51:03] mail+php at requinix dot net

Given a modified version of your script where $mainurl is explicitly set to the 
URL you give (in UTF-8) I get the expected XML.

It seems $venueArray has only the one item otherwise you would have discovered a 
large bug in your code. Are you sure $venueArray and $mainurl have the values you 
expect? You need to debug your script, and if you discover a real bug in PHP 
itself while doing so then you can (re)open a bug report with more specific 
information and something we can actually use to reproduce the problem.

Also, this is not the place to get help with your code. Find an online forum or 
mailing list to ask for assistance. That lets the PHP devs focus on bugs and gives 
you the personalized feedback you may need.

------------------------------------------------------------------------
[2012-12-26 05:20:40] sachinpkaushik at gmail dot com

Description:
------------
I am trying to generate xml file for sitemap for google tracking of my site url.

I have a php file with the code mentioned(Please refer the code sent) which I am 
running on the command line with no arguments.

The code retrieves value in an array $venueArrayfrom the value recieved from the 
function $venue->getAll()

There is a foreach loop which retrieves the value from the array '$venueArray'.

In the foreach loop I have added a code to fetch url from array '$venueArray' 
element 'id':- 

 $mainurl =$venue->getUrl(array("venueId"=>$venueD['id']));

and puts it in the xml tags with the help of the code

$url->addchild("loc",$mainurl);

and then the contents are appended in the file.

It seems that some of the urls are not added (url for example: 
http://mysite.com/dresden/769112-venue-theater-wechselbad-großer-saal)
in the 
following code intended to add urls:-

$url->addchild("loc",$mainurl);

Please provide me with the solution to my problem as soon as possible and also 
please let me know the changes which I should do in order to get urls in my xml 
file.

Some of the urls are not added in $url->addchild("loc",$mainurl);


Test script:
---------------
<?php
/** some of the urls are not added in $url->addchild("loc",$mainurl); **/

$xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"no\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"></urlset>";

$xmlobj = simplexml_load_string($xmltext);	

/** Code to retrieve venue array **/	  
$venue = new record();	   
		   
$venueArray=$venue->getAll();

/** End of the Code to retrieve venue array **/

foreach($venueArray as $venueD){
		   	   
			  /** Code to retrieve Url from venue array **/ 
			  $mainurl =$venue->getUrl(array("venueId"=>$venueD['id']));			
		       
			   /**
			   
			   Example of the url generated
			   	    
				http://mysite.com/dresden/769112-venue-theater-wechselbad-großer-saal
			
			   **/
			   		 
		    $url= $xmlobj->addChild("url");			
		    $url->addchild("loc",$mainurl);
		    $url->addChild("lastmod",date('Y-m-d'));
		    $url->addChild("changefreq","daily");
		    $url->addChild("priority","0.9");		

              $fp=fopen('test.xml',"a");
		      fwrite($fp,$xmlobj->asXML());
		      fclose($fp); 
}

?>

Expected result:
----------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>http://mysite.com/dresden/769112-venue-theater-wechselbad-großer-
saal</loc>
    <lastmod>2012-12-21</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.9</priority>
  </url>
</urlset>

Actual result:
--------------
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
  <loc/>
    <lastmod>2012-12-21</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.9</priority>
  </url>
</urlset>


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=63853&edit=1


Thread (4 messages)

« previous php.bugs (#183071) next »