Php 使用单个Xml创建Xml
我想创建一个这样的XML,但我做不到Php 使用单个Xml创建Xml,php,xml,Php,Xml,我想创建一个这样的XML,但我做不到 <content type="application/xml"> <m:properties> <d:Description>test</d:Description> <d:IncidentId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:IncidentId> <d:Respo
<content type="application/xml">
<m:properties>
<d:Description>test</d:Description>
<d:IncidentId m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:IncidentId>
<d:ResponsibleContactId m:type="Edm.Boolean" m:null="true" />
我的PHP代码:
$sxe = new SimpleXMLElement('<content></content>');
$prop = $sxe->addChild('m:proprieties');
$prop->addChild('d:Description', 'test');
$prop->addChild('d:IncidentId', '0');
$prop->addChild('d:ResponsibleContactId', '0');
返回不带前缀m和d的XML:
<content>
<proprieties>
<description>PHP2: More Parser Stories</description>
<incidentid>0</incidentid>
<responsiblecontactid>0</responsiblecontactid>
</proprieties>...
我怎么把我的前缀m:和d:?谢谢可能相关我不完全确定:尝试避开:,如:$prop->addChild'd \:IncidentId',0';另外,请确保拼写正确的单词properties。在添加名称空间前缀时,它可以正常工作。感谢$sxe=新的SimpleXMLElement;$prop=$sxe->addChild'm:properties',null,'m';$prop->addChild'd:Description','PHP2:More Parser Stories','d';$add=$prop->addChildd:IncidentId'0','d';$add->addAttribute'm:type'、'Edm.Guid'、'm';$prop->addChild'd:ResponsibleContactId',0',d'@jlaforgue回答您自己的问题并提出您的解决方案!