Results 1 to 2 of 2

Thread: convert json-String to XML problem

  1. #1
    Join Date
    Nov 2012

    convert json-String to XML problem

    Hi all,
    I am quite new in using php. I need to convert string bellow to XML. The string should comes from jquery(it is json object).

    {"@attributes":{"id":"3","name":"Cell"},"image":"images\/img1.jpg","linkItem":[{"@attributes":{"itemType":"reaction","itemId":"1","itemName":"O2 bubble exchange"},"area":[{"@attributes":{"width":"50","height":"250","top":"0","left":"150"}},{"@attributes":{"width":"100"," height":"250","top":"100","left":"150"}}],"point":{"@attributes":{"top":"200","left":"20"}}},{"@attributes":{"itemType":"entity","itemId":"1" ,"itemName":"CO2"},"area":[{"@attributes":{"width":"50","height":"300","top":"0","left":"250"}},{"@attributes":{"width":"10","h eight":"50","top":"300","left":"150"}}]}]}

    wanted XML structure is for example :

    <?xml version="1.0"encoding="UTF-8"?>
    <visualisation id="3"name="Cell">
    <linkItem itemType="reaction"itemId="1"itemName="O2d">
    <area width="50"height="250"top="0"left="150"/>
    <area width="100"height="250"top="100"left="150"/>
    <point top="200"left="20"/>
    <linkItem itemType="reaction"itemId="3"itemName="O2d">
    <area width="50"height="250"top="0"left="150"/>
    <area width="100"height="250"top="100"left="150"/>
    <point top="200"left="20"/>

    Please do you have some ideas to do that without need to create complicated parser ?
    thank you sooo much for answer ahead

  2. #2
    Join Date
    Aug 2004
    You can use json_decode() to get the JSON string into an array...
    PHP Code:
    $dataArray json_decode($jsonInputFromJquerytrue); 
    ...then see if you can process this via this class, perhaps?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center