Question

{"linkedin":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n
<skills total=\"11\">\n  
<skill>\n    
    <id>1<\/id>\n    
    <skill>\n      
        <name>C#<\/name>\n    
    <\/skill>\n  
<\/skill>\n  
<skill>\n    
    <id>2<\/id>\n    
    <skill>\n      
        <name>C<\/name>\n    
    <\/skill>\n  
<\/skill>\n  
........................
........................


$id =  getTextBetweenTags($user_profile['linkedin'], 'id');
      $fname = getTextBetweenTags($user_profile['linkedin'], 'first-name');
      $lname = getTextBetweenTags($user_profile['linkedin'], 'last-name');
      $pictureurl = getTextBetweenTags($user_profile['linkedin'], 'picture-url');
      $email = getTextBetweenTags($user_profile['linkedin'], 'email-address');
$headline = getTextBetweenTags($user_profile['linkedin'], 'headline'); 
$summary = getTextBetweenTags($user_profile['linkedin'], 'summary');  

    $interests=getTextBetweenTags($user_profile['linkedin'], 'interests'); 

$user_profile_skills = $OBJ_linkedin->profile('~/skills:(id,skill:(name))');  

$stringData = json_encode($user_profile_skills);
$xml = simplexml_load_string($stringData->linkedin);

How to retrive each value from it using php?. This is the JSON encoded form of skill set getting from linkedin. I am new to these kind of things. Please help me.

Was it helpful?

Solution

You've got an XML document inside your JSON object, so we need to do two things.

Decode the JSON:

$obj = json_decode($jsonString);

Use SimpleXML to parse the XML.

$xmlDoc = simplexml_load_string($obj->linkedin);

As long as the XML is correctly formatted you will be able to process it as your needs dictate using SimpleXML. Further information on SimpleXML can be found here: http://php.net/simplexml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top