如何使用PHP SimpleXMLElement删除名称空间?

如何使用PHP SimpleXMLElement删除名称空间?,php,simplexml,Php,Simplexml,我有一个XML结构,需要如下所示才能工作: <yq1:ZwsCreateInfoRec xmlns:yq1="urn:test-com:document:test:soap:functions:mc-style"> <ItPrice>1337</ItPrices> </yq1:ZwsCreateInfoRec> 出于某种原因,如果我在子节点上有这样的名称空间,那么WebService就不起作用,但是如果我删除它们,

我有一个XML结构,需要如下所示才能工作:

<yq1:ZwsCreateInfoRec xmlns:yq1="urn:test-com:document:test:soap:functions:mc-style">
      <ItPrice>1337</ItPrices>
</yq1:ZwsCreateInfoRec>
出于某种原因,如果我在子节点上有这样的名称空间,那么WebService就不起作用,但是如果我删除它们,它就会起作用。有没有一种方法可以让我删除它,或者我必须将它作为字符串循环并手动删除它们


谢谢

您可以为addChild方法使用第三个参数,该参数的值为空<代码>$xml->addChild('ItPrice','1337',''

$xml=新的SimpleXMLElement(“”);
$namespaces=$xml->getDocNamespaces();
$xml->addChild('ItPrice','1337','';
echo$xml->asXml();
这添加了一个类似于
1337
的标记,它的接缝与
1337
相同。对吗?`1337`它将删除
yq1
名称空间
$xml = SimpleXMLElement('<yq1:ZwsCreteMaterialFrRef xmlns:yq1="urn:test-com:document:test:soap:functions:mc-style"></yq1:ZwsCreteMaterialFrRef>');
$xml->addChild('ItPrice', '1337');
<yq1:ZwsCreateInfoRec xmlns:yq1="urn:test-com:document:test:soap:functions:mc-style">
      <yq1:ItPrice>1337</yq1:ItPrices>
</yq1:ZwsCreateInfoRec>
$xml = new SimpleXMLElement('<yq1:ZwsCreteMaterialFrRef xmlns:yq1="urn:test-com:document:test:soap:functions:mc-style"></yq1:ZwsCreteMaterialFrRef>');
$namespaces = $xml->getDocNamespaces();
$xml->addChild('ItPrice', '1337', '');
echo  $xml->asXml();