在PHP中使用命名空间URI生成XML [英] Generate XML with namespace URI in PHP

查看:101
本文介绍了在PHP中使用命名空间URI生成XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

呵呵,让这个简单的xml与php使用DOM?完整的代码将被欢迎。

 < rss version =2.0
xmlns:wp =http: /url.com
xmlns:dc =http://url2.com
>
< channel>
< items>
< sometag>< / sometags>
< wp:status>< / wp:status>
< / items>
< / channel>
< / rss>

我很迷失了。代码将帮助我更多的解释。

解决方案

如果你想简单,那么使用 SimpleXML ,而不是DOM。请注意,SimpleXML不会缩进XML。

  $ rss = simplexml_load_string('< rss version =2.0xmlns: wp =http://url.comxmlns:dc =http://url2.com/>'); 

$ channel = $ rss-> addChild('channel');
$ items = $ channel-> addChild('items');
$ sometags = $ items-> addChild('sometags');
$ status = $ items-> addChild('status',null,'http://url.com');

echo $ rss-> asXML();


Ho to make this "simple" xml with php using DOM? Full code will be welcomed.

<rss version="2.0"
  xmlns:wp="http://url.com"
  xmlns:dc="http://url2.com"
>
 <channel>
  <items>
   <sometags></sometags>
   <wp:status></wp:status>
  </items>
 </channel>
</rss>

i'm so lost. Code will help me more than any explanation.

解决方案

If you want "simple" then use SimpleXML, not DOM. Note that SimpleXML won't indent the XML.

$rss = simplexml_load_string('<rss version="2.0" xmlns:wp="http://url.com" xmlns:dc="http://url2.com" />');

$channel  = $rss->addChild('channel');
$items    = $channel->addChild('items');
$sometags = $items->addChild('sometags');
$status   = $items->addChild('status', null, 'http://url.com');

echo $rss->asXML();

这篇关于在PHP中使用命名空间URI生成XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆