www.webdeveloper.com
Results 1 to 2 of 2

Thread: convert json-String to XML problem

  1. #1
    Join Date
    Nov 2012
    Posts
    8

    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">
    <image>images/cell.png</image>
    <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>
    <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"/>
    </linkItem>
    </visualisation>



    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
    Location
    Ankh-Morpork
    Posts
    19,616
    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?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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



Recent Articles