0

Sample output data is below, it looks something like JSON, but it's not formatted exactly like JSON. So I am wondering, how can I get this data looking like XML, preferably with php?

[{
  action: 'getallregions',
  reply: [{
    regionid: '1',
    name: 'Blue',
    description: 'Research Route',
    color: '508CEB',
    active: 'true',
    parentRegionId: '0',
    parentRegion: ''
  }, {
    regionid: '4',
    name: 'Green',
    description: 'Vet School Route',
    color: '73BE69',
    active: 'true',
    parentRegionId: '0',
    parentRegion: ''
  }, {
    regionid: '10',
    name: 'Purple',
    description: 'Loop route',
    color: '5300B5',
    active: 'true',
    parentRegionId: '0',
    parentRegion: ''
  }]
}]

Here is the data on Pastie.org http://pastie.org/1045154

Mickael Lherminez
  • 679
  • 1
  • 10
  • 29

2 Answers2

0

You might be interested in topic "Is there some way to convert json to xml in PHP?"

Hope, that it helps you.

Community
  • 1
  • 1
Eugene
  • 4,352
  • 8
  • 55
  • 79
0

I don't know if this is what you are looking for, but:

json_decode(preg_replace('/([a-z0-9]+):/i','"$1":',str_replace('\'','"',$data)))

Basically I found a way to make the input valid JSON. The you can convert the object to xml using the XML_Serializer.

Narcis Radu
  • 2,519
  • 22
  • 33