मैं आउटपुट स्वरूपित करने की कोशिश कर रहा हूं कि आउटपुट होने पर मेरी एक्सएमएल फ़ाइल कैसी दिखती है। अभी अगर आप here पर जाएं और स्रोत देखें तो आप देखेंगे कि फ़ाइल कैसी दिखती है।PHP के साथ बनाए गए एक्सएमएल दस्तावेज़ - DomDocument
पीएचपी मैं है कि फ़ाइल बनाता है:, फ़ाइल के रूप में के रूप में पढ़ने योग्य नहीं है
header('Content-Type: text/xml');
$sitemap = new DOMDocument;
// create root element
$root = $sitemap->createElement("urlset");
$sitemap->appendChild($root);
$root_attr = $sitemap->createAttribute('xmlns');
$root->appendChild($root_attr);
$root_attr_text = $sitemap->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9');
$root_attr->appendChild($root_attr_text);
foreach($links_array as $http_url){
// create child element
$url = $sitemap->createElement("url");
$root->appendChild($url);
$loc = $sitemap->createElement("loc");
$lastmod = $sitemap->createElement("lastmod");
$changefreq = $sitemap->createElement("changefreq");
$url->appendChild($loc);
$url_text = $sitemap->createTextNode($http_url);
$loc->appendChild($url_text);
$url->appendChild($lastmod);
$lastmod_text = $sitemap->createTextNode(date("Y-m-d"));
$lastmod->appendChild($lastmod_text);
$url->appendChild($changefreq);
$changefreq_text = $sitemap->createTextNode("weekly");
$changefreq->appendChild($changefreq_text);
}
$file = "sitemap.xml";
$fh = fopen($file, 'w') or die("Can't open the sitemap file.");
fwrite($fh, $sitemap->saveXML());
fclose($fh);
}
आप स्रोत को देखकर बता सकते हैं के रूप में (ध्यान दें, $ links_array यूआरएल की एक सरणी है) मैं इसे होना चाहता हूँ। क्या मेरे लिए नोड्स को प्रारूपित करने का कोई तरीका है?
धन्यवाद,
लेवी
आप एक एक्सएमएल हेडर जोड़ सकते हैं और इसे फ़ायरफ़ॉक्स में खोल सकते हैं। यह आपके एक्सएमएल दस्तावेज़ –