从PHP函数生成XML(我做错了什么?)
下面是一个生成一些XML的简单php脚本:从PHP函数生成XML(我做错了什么?),php,xml,wordpress,Php,Xml,Wordpress,下面是一个生成一些XML的简单php脚本: <?php // create doctype $dom = new DOMDocument("1.0"); // display document in browser as plain text header("Content-Type: text/plain"); // create root element $root = $dom->createElement("page"); $dom->appendChild($ro
<?php
// create doctype
$dom = new DOMDocument("1.0");
// display document in browser as plain text
header("Content-Type: text/plain");
// create root element
$root = $dom->createElement("page");
$dom->appendChild($root);
// loop through all posts
while (have_posts()) : the_post();
// create child element
$item = $dom->createElement("title");
$root->appendChild($item);
// add title data
$text = $dom->createTextNode(the_title());
$item->appendChild($text);
endwhile;
// save and display tree
echo $dom->saveXML();
?>
生成的XML是(这正是我想要的):
标题在这里,标题在这里
标题()是一个Wordpress函数,我正在尝试以XML格式呈现页面 我认为像_post()和_title()这样的函数会立即输出值,而不是返回值。其中一些具有等价物,如get_the*(),它将返回值而不是打印;这可能是你想要的
可能有用我认为像_post()和_title()这样的函数会立即输出值,而不是返回值。其中一些具有等价物,如get_the*(),它将返回值而不是打印;这可能是你想要的
可能有用我也不建议使用DOMDocument生成XML。这是相当缓慢和内存消耗。考虑使用XMLWror或PuPro PHP方式。 < P>我也不推荐使用DOMBOOST来推荐<强> >生成<强> XML。这是相当缓慢和内存消耗。考虑使用XMLWror或“PuPrPHP”方式。你能告诉我们在SythTyle()函数中有什么吗?你能告诉我们在SythTyle()函数中有什么吗?超级!我想如果我在某个地方提到WordPress会有所帮助。谢谢你的帮助。太好了!我想如果我在某个地方提到WordPress会有所帮助。谢谢你的帮助。谢谢FractalizeR,谢谢你的提示!谢谢FractalizeR,谢谢你的提示!
This is my second postHello world!<?xml version="1.0"?>
<page><title></title><title></title></page>
$text = $dom->createTextNode("Title-goes-here");
<?xml version="1.0"?>
<page><title>Title-goes-here</title><title>Title-goes-here</title></page>