这是在我的xml文件中:
<?xml version="1.0" ?>
- <AXISWeb xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="AXISWeb.xsd">
<Membership>
<ExpiryDate />
<MemStatus />
<MemStatusDesc />
<RenewType />
<!-- I want new node here with php code -->
</Membership>
<Address>
<address1/>
...
</Address>
</AXISWeb>
这种类型的解决方案用其他语言但不是在PHP请求,任何人都可以为此提供帮助
感谢。
答案 0 :(得分:-1)
以下是您的问题的解决方案:
<?php
$xmldoc = new DOMDocument();
//xmldata.xml contains your xml data.
$xmldoc->load('xmldata.xml');
//if you want to add child under AXISWeb node
$root = $xmldoc->firstChild;
//otherwise use this line
//index = index of parent node such as for "Membership" it is 0. So just replace index with 0.
$root=xmlDoc.getElementsByTagName("AXISWeb")[index];
$newElement = $xmldoc->createElement('newchild');
$root->appendChild($newElement);
$xmldoc->save('xmldata.xml');
?>