Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION CDATA IN SITEMAP.XML
#1
Good evening

I am Brazilian, and I love that content manager! (Get-Simple)


I have a question in relation to sitemap.xml

I know that the file creation function is to: generate_sitemap () located in the \admin\inc\template_functions.php


I wanted to know how to include for example: <loc>Lorem ipsum dolore</loc> generate as follows: <loc><![CDATA["Lorem ipsum dolore"]]></loc>

Please help me.
Reply
#2
You have to change the source or write your own function and use ->addCData instead of addChild
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
(2015-07-01, 11:38:03)shawn_a Wrote: You have to change the source or write your own function and use ->addCData instead of addChild

I did it, but when loading the admin / sitemap.php?refresh the page does not load Sad
Reply
#4
Well you have to change it a bit to create the element. See how it's done in other code that saved data like change data.php
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
PHP Code:
        $note $xml->addChild('url');
        
$note->addCData($url); 
You have to still add the element but also add cdata to it.
Not the easiest code but all we have for now.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#6
You have a whatsapp?
i invite message in facebook, please
Reply
#7
I'm on mobile, I'll post actual code or someone else will soon I'm sure
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#8
Thank you, here in Brazil is 23:12, it's late.


Who can help me, I thank you.

I am creating several xml files, I will make integration between systems via XML and the good word of the cdata is required.

Please help me, I could not resolve and I am two days trying
Reply
#9
Do you only need it for <loc> or all fields?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#10
This generate_sitemap() will do what you want for the <loc> field.
The xml had to be changed to our SimpleXMLExtended to include the cdata function.

note that the i18n nav plugin uses its own function!

This will probably not work correctly though since the urls are already encoded, you probably have to entitydecode them in the cdata now.

PHP Code:
/**
 * Creates Sitemap
 *
 * Creates sitemap.xml in the site's root.
 */
function generate_sitemap() {

    if(
getDef('GSNOSITEMAP',true)) return;

    
// Variable settings
    
global $SITEURL;
    
$path GSDATAPAGESPATH;
    
    global 
$pagesArray;
    
getPagesXmlValues(false);
    
$pagesSorted subval_sort($pagesArray,'menuStatus');
    
    if (
count($pagesSorted) != 0)
    { 
        
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><urlset></urlset>');
        
$xml->addAttribute('xsi:schemaLocation''http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd''http://www.w3.org/2001/XMLSchema-instance');
        
$xml->addAttribute('xmlns''http://www.sitemaps.org/schemas/sitemap/0.9');
        
        foreach (
$pagesSorted as $page)
        {
            if (
$page['url'] != '404')
            {        
                if (
$page['private'] != 'Y')
                {
                    
// set <loc>
                    
$pageLoc find_url($page['url'], $page['parent']);
                    
                    
// set <lastmod>
                    
$tmpDate date("Y-m-d H:i:s"strtotime($page['pubDate']));
                    
$pageLastMod makeIso8601TimeStamp($tmpDate);
                    
                    
// set <changefreq>
                    
$pageChangeFreq 'weekly';
                    
                    
// set <priority>
                    
if ($page['menuStatus'] == 'Y') {
                        
$pagePriority '1.0';
                    } else {
                        
$pagePriority '0.5';
                    }
                    
                    
//add to sitemap
                    
$url_item $xml->addChild('url');
                    
                    
$item $url_item->addChild('loc');
                    
$item->addCData($pageLoc);
                    
                    
$url_item->addChild('lastmod'$pageLastMod);
                    
$url_item->addChild('changefreq'$pageChangeFreq);
                    
$url_item->addChild('priority'$pagePriority);
                }
            }
        }
        
        
//create xml file
        
$file GSROOTPATH .'sitemap.xml';
        
$xml exec_filter('sitemap',$xml);
        
XMLsave($xml$file);
        
exec_action('sitemap-aftersave');
    }
    
    if (!
defined('GSDONOTPING')) {
        if (
file_exists(GSROOTPATH .'sitemap.xml')){
            if( 
200 === ($status=pingGoogleSitemaps($SITEURL.'sitemap.xml')))    {
                
#sitemap successfully created & pinged
                
return true;
            } else {
                
error_log(i18n_r('SITEMAP_ERRORPING'));
                return 
i18n_r('SITEMAP_ERRORPING');
            }
        } else {
            
error_log(i18n_r('SITEMAP_ERROR'));
            return 
i18n_r('SITEMAP_ERROR');
        }
    } else {
        
#sitemap successfully created - did not ping
        
return true;
    }

NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#11
Why do you need cdata in sitemaps?
I am not sure if that is supported by search engines entirely.

Google says to use entity escape codes, not cdata.
https://support.google.com/webmasters/an...5653?hl=en
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#12
Good evening , I'm coming home and I will test the code . In fact need to generate multiple xml files for use in web service integration , will keep the site map integrity , some of these files will need cdata ... I thank performance. THANK YOU VERY MUCH
Reply
#13
(2015-07-01, 23:11:31)shawn_a Wrote: Why do you need cdata in sitemaps?
I am not sure if that is supported by search engines entirely.

Google says to use entity escape codes, not cdata.
https://support.google.com/webmasters/an...5653?hl=en

Good night, it worked!


I have a question, I want to generate like this link: http://imofox.com.br/imofox.xml 

How to generate a single tag for example the link: <imovel> involving the entire file

and end tags make a repetition, for example:

<Photos>
<picture>
<foto_url>
<! [CDATA []]>
</ foto_url>
</ picture>
<picture>
<foto_url>
<! [CDATA []]>
</ foto_url>
</ picture>
<picture>
<foto_url>
<! [CDATA []]>
</ foto_url>
</ picture>
</ Photos>
Reply




Users browsing this thread: 1 Guest(s)