note 117981 added to simplexmlelement.addchild

From: Date: Mon, 14 Sep 2015 13:27:37 +0000
Subject: note 117981 added to simplexmlelement.addchild
Groups: php.notes 
Request: Send a blank email to php-notes+get-203776@lists.php.net to get a copy of this message
In the docs for google sitemaps it is required an element for mobile sitemaps that looks like this: <mobile:mobile/> I used some time to figure out how to make it, but it is quite simple when understood. $mobile_schema = 'http://www.google.com/schemas/sitemap-mobile/1.0'; //Create root element $xml_mobile = new SimpleXMLElement(' <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:mobile="'.$mobile_schema.'"></urlset> '); //Add required children $url_mobile = $xml_b_list_mobile->addChild('url'); $url_mobile->addChild('loc', 'your-mobile-site-url'); $url_mobile->addChild('mobile:mobile', null, $mobile_schema); For this to work properly the attribute xmlns:mobile must be set in the root node, and then used as namespace(third argument) when creating the mobile:mobile child with null as value. ---- Server IP: 72.52.91.14 Probable Submitter: 80.91.33.138 ---- Manual Page -- http://php.net/manual/en/simplexmlelement.addchild.php Edit -- https://master.php.net/note/edit/117981 Del: integrated -- https://master.php.net/note/delete/117981/integrated Del: useless -- https://master.php.net/note/delete/117981/useless Del: bad code -- https://master.php.net/note/delete/117981/bad+code Del: spam -- https://master.php.net/note/delete/117981/spam Del: non-english -- https://master.php.net/note/delete/117981/non-english Del: in docs -- https://master.php.net/note/delete/117981/in+docs Del: other reasons-- https://master.php.net/note/delete/117981 Reject -- https://master.php.net/note/reject/117981 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203776) next »