dongma6326 2016-08-10 14:24
浏览 34

尝试使用PHP和DOMDocument创建带有名称空间的XML

I am attempting to create an XML file using PHP 5.6.24 and DOMDocument. The format of the XML is supposed to be as follows:

<parks xmlns:tch="{urn}" xmlns:prk="{urn}">

It is my understanding that the following block of code:

$root = $doc->createElementNS('http://www.w3.org/2005/Atom', 'element');
$doc->appendChild($root);
$root->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:g', 'http://base.google.com/ns/1.0');
$item = $doc->createElementNS('http://base.google.com/ns/1.0', 'g:item_type', 'house');
$root->appendChild($item);

Will allow me to produce the following output:

<element xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">
    <g:item_type>house</g:item_type>
</element>

The problem with this is that this method only allows me to add one tagname as opposed to the two that I need (tch and prk).

Is it possible to achieve this result using the DOMDocument library or is there something better for this situation.

Thank you in advanced!!!!!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?