Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在旧xml数据之前设置新xml数据 load('rss.xml'); $title=$_POST['title']; $image=$_POST['image']; $user=$_POST['user']; $date=日期(“Y/m/d”); $indent=$_POST['indent']; $description=$_POST['description']; $rootTag=$xml->documentElement; $entryTag=$xml->createElement(“条目”); $titleTag=$xml->createElement(“title”,$title); $imageTag=$xml->createElement(“图像”,$image); $userTag=$xml->createElement(“用户”,$user); $dateTag=$xml->createElement(“日期”,$date); $indentTag=$xml->createElement(“缩进”,“缩进”); $descriptionTag=$xml->createElement(“描述”,$description); $entryTag->appendChild($titleTag); $entryTag->appendChild($imageTag); $entryTag->appendChild($userTag); $entryTag->appendChild($dateTag); $entryTag->appendChild($indentTag); $entryTag->appendChild($descriptionTag); $rootTag->appendChild($entryTag); $xml->save('rss.xml'); } ?>_Php_Xml_Dom_Rss - Fatal编程技术网

Php 在旧xml数据之前设置新xml数据 load('rss.xml'); $title=$_POST['title']; $image=$_POST['image']; $user=$_POST['user']; $date=日期(“Y/m/d”); $indent=$_POST['indent']; $description=$_POST['description']; $rootTag=$xml->documentElement; $entryTag=$xml->createElement(“条目”); $titleTag=$xml->createElement(“title”,$title); $imageTag=$xml->createElement(“图像”,$image); $userTag=$xml->createElement(“用户”,$user); $dateTag=$xml->createElement(“日期”,$date); $indentTag=$xml->createElement(“缩进”,“缩进”); $descriptionTag=$xml->createElement(“描述”,$description); $entryTag->appendChild($titleTag); $entryTag->appendChild($imageTag); $entryTag->appendChild($userTag); $entryTag->appendChild($dateTag); $entryTag->appendChild($indentTag); $entryTag->appendChild($descriptionTag); $rootTag->appendChild($entryTag); $xml->save('rss.xml'); } ?>

Php 在旧xml数据之前设置新xml数据 load('rss.xml'); $title=$_POST['title']; $image=$_POST['image']; $user=$_POST['user']; $date=日期(“Y/m/d”); $indent=$_POST['indent']; $description=$_POST['description']; $rootTag=$xml->documentElement; $entryTag=$xml->createElement(“条目”); $titleTag=$xml->createElement(“title”,$title); $imageTag=$xml->createElement(“图像”,$image); $userTag=$xml->createElement(“用户”,$user); $dateTag=$xml->createElement(“日期”,$date); $indentTag=$xml->createElement(“缩进”,“缩进”); $descriptionTag=$xml->createElement(“描述”,$description); $entryTag->appendChild($titleTag); $entryTag->appendChild($imageTag); $entryTag->appendChild($userTag); $entryTag->appendChild($dateTag); $entryTag->appendChild($indentTag); $entryTag->appendChild($descriptionTag); $rootTag->appendChild($entryTag); $xml->save('rss.xml'); } ?>,php,xml,dom,rss,Php,Xml,Dom,Rss,我想在其他元素之前插入这个,我可以得到帮助,并且这个编码可以工作吗 这就是我想要它做的: 旧xml 我们回来了 assets/img/scape-mountains-nature-clouds.jpg 游戏管理员 1/14/16 它是 我们在2016年发布的第一篇帖子,抱歉,网站已经关闭。我们一直在努力为消费者群集成登录系统。我们感谢您抽出时间等待,并希望您在不久的将来享受来自我们公司的新更新。我们仍在寻找合作伙伴,因此请加入我们的行列,并注册该公司,以便我们能够制作游戏! 表单提交后的新X

我想在其他元素之前插入这个,我可以得到帮助,并且这个编码可以工作吗

这就是我想要它做的:

旧xml


我们回来了
assets/img/scape-mountains-nature-clouds.jpg
游戏管理员
1/14/16
它是
我们在2016年发布的第一篇帖子,抱歉,网站已经关闭。我们一直在努力为消费者群集成登录系统。我们感谢您抽出时间等待,并希望您在不久的将来享受来自我们公司的新更新。我们仍在寻找合作伙伴,因此请加入我们的行列,并注册该公司,以便我们能够制作游戏!
表单提交后的新XML


测试
测试
测试
2016/03/31
测试
测试
我们回来了
assets/img/scape-mountains-nature-clouds.jpg
游戏管理员
1/14/16
它是
我们在2016年发布的第一篇帖子,抱歉,网站已经关闭。我们一直在努力为消费者群集成登录系统。我们感谢您抽出时间等待,并希望您在不久的将来享受来自我们公司的新更新。我们仍在寻找合作伙伴,因此请加入我们的行列,并注册该公司,以便我们能够制作游戏!

如果你能帮我编写代码,那就真的需要它,这样它就不会以错误的方式打印提要了

该方法被称为
DOMDocument::getElementsByTagName()
。它返回一个
DOMNodeList
。要获取节点列表的第一个元素,请使用
DOMNodeList::item()

rss提要的根标记(文档元素)应该是
rss
,而不是
roo
。文档元素也可以在
DOMDocument::$documentElement
属性中找到:

$rootTag = $xml->getElementsByTagName("roo")->item(0);
另外,返回附加的节点。这允许它与
DOMDocument::create*
方法相结合。您不应该为
DOMDocument::createElement()
使用第二个参数。下面是一个可能导致XML损坏的错误。创建和附加文本节点:

$rootTag = $xml->documentElement;
输出:

$document = new DomDocument("1.0","UTF-8");
$document->appendChild($document->createElement('rss'));

$title = 'A Title';
$image = 'foo.png';
$description = 'Some text';

$rootTag = $document->documentElement;

$entryTag = $rootTag->appendChild($document->createElement("entry"));
$entryTag
  ->appendChild($document->createElement("title"))
  ->appendChild($document->createTextNode($title));
$entryTag
  ->appendChild($document->createElement("image"))
  ->appendChild($document->createTextNode($image));
$entryTag
  ->appendChild($document->createElement("description"))
  ->appendChild($document->createTextNode($description));

$document->formatOutput = TRUE;
echo $document->saveXml();

头衔
foo.png
一些文本

如果放置
echo gettype($xml);模具()在线#13,它是否输出
对象
?是的,它剂量输出对象这可能很有用,
$rootTag = $xml->getElementsByTagName("roo")->item(0);
$rootTag = $xml->documentElement;
$document = new DomDocument("1.0","UTF-8");
$document->appendChild($document->createElement('rss'));

$title = 'A Title';
$image = 'foo.png';
$description = 'Some text';

$rootTag = $document->documentElement;

$entryTag = $rootTag->appendChild($document->createElement("entry"));
$entryTag
  ->appendChild($document->createElement("title"))
  ->appendChild($document->createTextNode($title));
$entryTag
  ->appendChild($document->createElement("image"))
  ->appendChild($document->createTextNode($image));
$entryTag
  ->appendChild($document->createElement("description"))
  ->appendChild($document->createTextNode($description));

$document->formatOutput = TRUE;
echo $document->saveXml();
<?xml version="1.0" encoding="UTF-8"?>
<rss>
  <entry>
    <title>A Title</title>
    <image>foo.png</image>
    <description>Some text</description>
  </entry>
</rss>