0

I would like to create an XML like this but I can not do it ..

<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" />

My code in 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');

Return this XML without prefix m and d:

<content>
<proprieties>
  <description>PHP2: More Parser Stories</description>
  <incidentid>0</incidentid>
  <responsiblecontactid>0</responsiblecontactid>
</proprieties>...

How do I put my prefix "m:" and "d:"? Thanks

jlafforgue
  • 287
  • 2
  • 5
  • 15
  • 1
    Possibly related (I'm not entirely sure): [adding a namespace when using SimpleXMLElement](http://stackoverflow.com/q/6927567) – Pekka Jan 11 '14 at 00:04
  • Try to escape the `:`, like this: `$prop->addChild('d\:IncidentId', '0');` also, make sure you spell correctly the word "properties" – Pedro Lobito Jan 11 '14 at 00:08
  • 1
    It works fine when i add namespace prefix. Thanks `$sxe = new SimpleXMLElement(''); $prop = $sxe->addChild('m:properties', null, 'm'); $prop->addChild('d:Description', 'PHP2: More Parser Stories', 'd'); $add = $prop->addChild("d:IncidentId", '0', 'd'); $add->addAttribute('m:type', 'Edm.Guid', 'm'); $prop->addChild('d:ResponsibleContactId', '0', 'd');` – jlafforgue Jan 11 '14 at 00:23
  • @jlafforgue answer your own question and present your solution! – michi Jan 11 '14 at 22:30

0 Answers0