php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63853 Some of the urls are not added in $url->addchild("loc",$mainurl);
Submitted: 2012-12-26 05:20 UTC Modified: 2014-12-30 10:41 UTC
From: sachinpkaushik at gmail dot com Assigned:
Status: No Feedback Package: DOM XML related
PHP Version: 5.4.10 OS: Fedora Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sachinpkaushik at gmail dot com
New email:
PHP Version: OS:

 

 [2012-12-26 05:20 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-31 22:51 UTC] 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.
 [2013-12-02 16:32 UTC] mike@php.net
-Status: Open +Status: Feedback
 [2013-12-02 16:32 UTC] mike@php.net
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.


 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 09:01:28 2024 UTC