/    Sign up×
Community /Pin to ProfileBookmark

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″,”height”:”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 ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 28.2013 — You can use json_decode() to get the JSON string into an array...
[code=php]
$dataArray = json_decode($jsonInputFromJquery, true);
[/code]
...then see if you can process this via [url=http://www.lalit.org/lab/convert-php-array-to-xml-with-attributes/]this class[/url], perhaps?
×

Success!

Help @dedtadeas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...