0

I wanted to take the fields such as School Type, Name, Location, Details, Degreemjor, Education details, Start and End Date

How can i do this using the foreach loop ?

Here is my Array.

    Array (
    [0] => SimpleXMLElement Object (
    [@attributes] => Array (
    [SchoolType] => UnSpecified
    )
    [School] => SimpleXMLElement Object (
    [SchoolName] => School of
    )
    [SchoolLocation] => SimpleXMLElement Object (
    )
    [Degree] => SimpleXMLElement Object (
    [@attributes] => Array (
    [DegreeType] =>
    )
    [IsHighestDegee] => True
    [DegreeName] => SimpleXMLElement Object (
    )
    [DegreeDate] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [DegreeMajor] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EducationDetails] => SimpleXMLElement Object (
    )
    [DegreeMeasure] => SimpleXMLElement Object (
    [EducationMeasure] => SimpleXMLElement Object (
    [MeasureSystem] => SimpleXMLElement Object (
    )
    [MeasureValue] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    )
    )
    [DateofAttendance] => SimpleXMLElement Object (
    [StartDate] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EndDate] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    )
    [EducationDescription] => Editor - School of Business Management Students\' newsletter
    )
    )
    [1] => SimpleXMLElement Object (
    [@attributes] => Array (
    [SchoolType] => UnSpecified
    )
    [School] => SimpleXMLElement Object (
    [SchoolName] => Nanyang Polytechnic
    )
    [SchoolLocation] => Nanyang
    [Degree] => SimpleXMLElement Object (
    [@attributes] => Array (
    [DegreeType] => Certificate Courses
    )
    [IsHighestDegee] => False
    [DegreeName] => SimpleXMLElement Object (
    )
    [DegreeDate] => SimpleXMLElement Object (
    [AnyDate] => 1/1/1999
    )
    [DegreeMajor] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EducationDetails] => Engineering
    [DegreeMeasure] => SimpleXMLElement Object (
    [EducationMeasure] => SimpleXMLElement Object (
    [MeasureSystem] => SimpleXMLElement Object (
    )
    [MeasureValue] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    )
    )
    [DateofAttendance] => SimpleXMLElement Object (
    [StartDate] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EndDate] => SimpleXMLElement Object (
    [AnyDate] => 1/1/1999
    )
    )
    [EducationDescription] => Secretary - Nanyang Polytechnic Students\' Union Participated in inter-diploma debate (
    1999
    ) - preliminary and semi-final
    )
    )
    [2] => SimpleXMLElement Object (
    [@attributes] => Array (
    [SchoolType] => UnSpecified
    )
    [School] => SimpleXMLElement Object (
    [SchoolName] => Member of school volleyball team - represented school in National competition
    )
    [SchoolLocation] => SimpleXMLElement Object (
    )
    [Degree] => SimpleXMLElement Object (
    [@attributes] => Array (
    [DegreeType] => Certificate Courses
    )
    [IsHighestDegee] => False
    [DegreeName] => SimpleXMLElement Object (
    )
    [DegreeDate] => SimpleXMLElement Object (
    [AnyDate] => 1/1/1996
    )
    [DegreeMajor] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EducationDetails] => Engineering
    [DegreeMeasure] => SimpleXMLElement Object (
    [EducationMeasure] => SimpleXMLElement Object (
    [MeasureSystem] => SimpleXMLElement Object (
    )
    [MeasureValue] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    )
    )
    [DateofAttendance] => SimpleXMLElement Object (
    [StartDate] => SimpleXMLElement Object (
    [0] => SimpleXMLElement Object (
    )
    )
    [EndDate] => SimpleXMLElement Object (
    [AnyDate] => 1/1/1996
    )
    )
    [EducationDescription] => Patrol Leader - Girl Guides Member of school volleyball team - represented school in National competition - clinched 2nd prize in 1996
    )
    )
    )

Here is the var_export

array (
0 => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'SchoolType\' => \'UnSpecified\',
), \'School\' => SimpleXMLElement::__set_state(
array(
\'SchoolName\' => \'School of\',
)
), \'SchoolLocation\' => SimpleXMLElement::__set_state(
array(
)
), \'Degree\' => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'DegreeType\' => \'\',
), \'IsHighestDegee\' => \'True\', \'DegreeName\' => SimpleXMLElement::__set_state(
array(
)
), \'DegreeDate\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)
), \'DegreeMajor\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
), )), \'EducationDetails\' => SimpleXMLElement::__set_state(
array(
)), \'DegreeMeasure\' => SimpleXMLElement::__set_state(
array(
\'EducationMeasure\' => SimpleXMLElement::__set_state(
array(
\'MeasureSystem\' => SimpleXMLElement::__set_state(
array(
)
), \'MeasureValue\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), )), )), \'DateofAttendance\' => SimpleXMLElement::__set_state(
array(
\'StartDate\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), \'EndDate\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
), )), )), \'EducationDescription\' => \'Editor - School of Business Management Students\\\' newsletter\', )), )), 1 => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'SchoolType\' => \'UnSpecified\',
), \'School\' => SimpleXMLElement::__set_state(
array(
\'SchoolName\' => \'Nanyang Polytechnic\',
)
), \'SchoolLocation\' => \'Nanyang\', \'Degree\' => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'DegreeType\' => \'Certificate Courses\',
), \'IsHighestDegee\' => \'False\', \'DegreeName\' => SimpleXMLElement::__set_state(
array(
)
), \'DegreeDate\' => SimpleXMLElement::__set_state(
array(
\'AnyDate\' => \'1/1/1999\',
)), \'DegreeMajor\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
), )), \'EducationDetails\' => \'Engineering\', \'DegreeMeasure\' => SimpleXMLElement::__set_state(
array(
\'EducationMeasure\' => SimpleXMLElement::__set_state(
array(
\'MeasureSystem\' => SimpleXMLElement::__set_state(
array(
)
), \'MeasureValue\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), )), )), \'DateofAttendance\' => SimpleXMLElement::__set_state(
array(
\'StartDate\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), \'EndDate\' => SimpleXMLElement::__set_state(
array(
\'AnyDate\' => \'1/1/1999\',
)), )), \'EducationDescription\' => \'Secretary - Nanyang Polytechnic Students\\\' Union Participated in inter-diploma debate (
1999
) - preliminary and semi-final\', )), )), 2 => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'SchoolType\' => \'UnSpecified\',
), \'School\' => SimpleXMLElement::__set_state(
array(
\'SchoolName\' => \'Member of school volleyball team - represented school in National competition\',
)
), \'SchoolLocation\' => SimpleXMLElement::__set_state(
array(
)), \'Degree\' => SimpleXMLElement::__set_state(
array(
\'@attributes\' => array (
\'DegreeType\' => \'Certificate Courses\',
), \'IsHighestDegee\' => \'False\', \'DegreeName\' => SimpleXMLElement::__set_state(
array(
)
), \'DegreeDate\' => SimpleXMLElement::__set_state(
array(
\'AnyDate\' => \'1/1/1996\',
)), \'DegreeMajor\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
), )), \'EducationDetails\' => \'Engineering\', \'DegreeMeasure\' => SimpleXMLElement::__set_state(
array(
\'EducationMeasure\' => SimpleXMLElement::__set_state(
array(
\'MeasureSystem\' => SimpleXMLElement::__set_state(
array(
)
), \'MeasureValue\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), )), )), \'DateofAttendance\' => SimpleXMLElement::__set_state(
array(
\'StartDate\' => SimpleXMLElement::__set_state(
array(
0 => SimpleXMLElement::__set_state(
array(
)
),
)), \'EndDate\' => SimpleXMLElement::__set_state(
array(
\'AnyDate\' => \'1/1/1996\',
)), )), \'EducationDescription\' => \'Patrol Leader - Girl Guides Member of school volleyball team - represented school in National competition - clinched 2nd prize in 1996\', )), )), )

This is the following up of this question

Community
  • 1
  • 1
  • 1
    Follow up? It looks like an identical question? – Luke May 19 '15 at 04:15
  • That is for a single array and this is for the multiple array, ( Foreach will be employed here) –  May 19 '15 at 04:16
  • do an if(___||___||___) inside the for each statement based upon what you want triggered. – a coder May 19 '15 at 04:17
  • @php_purest Can you please explain in it code.. –  May 19 '15 at 04:18
  • It'd help if the array was better indented. Can you please update your first post with a properly formatted array? How much experience do you have with programming/with PHP? – Luke May 19 '15 at 04:19
  • You wanted `var_dump` or `var_export` instead of `print_r` ? –  May 19 '15 at 04:21
  • 2
    @StackRaja I can, but if you can't even write an if statement within a for each that you have running, why are you writing code by hand? – a coder May 19 '15 at 04:24
  • Surprise me. Just keep the indentation when you copy it into the question. You may need to mark it as code in the post editor. – Luke May 19 '15 at 04:24
  • @php_purest If you explain the meaning of `if(||___||) ` i can do it –  May 19 '15 at 04:28
  • @Luke I believe that the above array is given inside the `code` format –  May 19 '15 at 04:29
  • That was a stack overflow system bug, but || means or – a coder May 19 '15 at 04:30
  • When you dumped, it didn't have whitespace at the start of lines to indent properly? Am I insane, am I the only one who doesn't see neat code? :S – Luke May 19 '15 at 04:31
  • Sigh, okay, if you could do a var_export() instead for me, please? Then I'll see if I can edit your first post. – Luke May 19 '15 at 04:32

2 Answers2

2

Have a look at SimpleXMLElement::attributes

I think you can get the element like

$url = 'http://recruitplushrxmlapidemo.onlineresumeparser.com/hrxml/153Melanie%20R.%20Mather%20Mills.xml';

$sxml = simplexml_load_file($url);

foreach($sxml->StructuredXMLResume->EducationHistory->SchoolOrInstitution as $key => $value){

    echo 'SchoolType --> '.$value->attributes()['SchoolType'];        
    echo "<br />";
    echo 'SchoolName --> '.$value->School->SchoolName;
    echo "<br />";
    echo 'SchoolLocation --> '.$value->SchoolLocation;
    echo "<br />";
    echo 'DegreeMajor --> '.$value->Degree->DegreeMajor[0];
    echo "<br />";
    echo 'EducationDetails --> '.$value->Degree->EducationDetails;
    echo "<br />";
    echo 'StartDate --> '.$value->Degree->DateofAttendance->StartDate[0];
    echo "<br />";
    echo 'EndDate --> '.$value->Degree->DateofAttendance->EndDate->AnyDate;
    echo "<br /><br />";

}
Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46
  • Hi, thanks, i am getting the SchoolType i.e., unspecified .. can you please tell how to get the **School Type, Name, Location, Details, Degreemjor, Education details, Start and End Date** also ? –  May 19 '15 at 04:43
  • Thats not a big deal you can do it by yourself, format your question if you want more help – Praveen Dabral May 19 '15 at 04:49
  • Actually, i can't able to post the formatted code in stackoverflow, here is the eval sample code link https://eval.in/367010 –  May 19 '15 at 04:53
  • I tried `$key['School']->SchoolName` and i am getting empty frield :( –  May 19 '15 at 05:06
  • I don't understand how this is so strangely formatted :S anyway, @StackRaja, can't you see how to apply the above to get different attributes? Maybe try adding `echo $attr['SchoolName'];` into that loop? – Luke May 19 '15 at 05:06
  • I too The reason was, the array was being printed as the output of an API .... :( it looks strange .. when i try to `echo $attr['SchoolName'];` inside the loop, i got nothing.. its was empty .. –  May 19 '15 at 05:08
  • If seeing the array is problem, i can show the printed array in the teamviewer for you :) –  May 19 '15 at 05:08
  • You can get the school name like --> $value['School']['SchoolName'] – Praveen Dabral May 19 '15 at 05:21
  • Let me know the api url from where you are accessing these details – Praveen Dabral May 19 '15 at 05:25
  • @tiGer I tried `echo $value['School']['SchoolName'] ;` But can't get anything –  May 19 '15 at 05:34
  • Here is the url of getting those arrya http://recruitplushrxmlapidemo.onlineresumeparser.com/hrxml/153Melanie%20R.%20Mather%20Mills.xml and http://recruitplushrxmlapidemo.onlineresumeparser.com/hrxml/154NANCY%20J.%20DACEY-BALSAMO.xml I am saving it as xml and loading converting it to an array –  May 19 '15 at 05:36
  • Thanks for the being short. It was helpful !! –  May 19 '15 at 06:22
  • Hi, can you please Help me in this question http://stackoverflow.com/q/30318180/3492495 –  May 19 '15 at 09:19
  • I think you can do that in same way, format your question using --> echo '
    '; print_r($array);
    – Praveen Dabral May 19 '15 at 09:22
1

I'm an idiot, it didn't click that that was XML. Okay, so your array appears to be an array of schools/institutions from a resume, correct? Just follow the XML hierarchy to reach each node that you care about.

foreach ($nodes as $node) {
    echo "Type: " . $node->attributes()['SchoolType'] . "\n";
    echo "Name: " . $node->School->SchoolName . "\n";
    echo "Location: " . $node->SchoolLocation . "\n";
    echo "Degree name: " . $node->Degree->DegreeName . "\n";
    // etc
}
Luke
  • 1,724
  • 1
  • 12
  • 17
  • Hopefully... :) How did you populate that array? You should include that code in your original post, too. – Luke May 19 '15 at 06:16
  • Wow !!!!! It was awesome !!! You're the man :) Can you please how to get the value `ResumeParsingStartDate` in this array ... https://eval.in/367046 here is the original post of array http://stackoverflow.com/questions/30022826/how-to-get-the-exact-value-from-the-array-php –  May 19 '15 at 06:18
  • Yep, I'll have a look. Please accept the answer? :) – Luke May 19 '15 at 06:19
  • Oh, actually i save that file as .xml and the convert it into array and then doing it –  May 19 '15 at 06:20
  • Yep. Same is this, really. Check @tiGer's answer, that's quite good. – Luke May 19 '15 at 06:20
  • Wow, thank you for being gentle,, i am upvoting twice ;) your answer and i shall ask it in a seperate question and convey you.. Really thanks –  May 19 '15 at 06:22
  • Hi, here is the question i asked on that, can you please have a look on it sir..http://stackoverflow.com/questions/30316654/how-can-i-get-particular-fields-in-the-array-using-foreach/30317996#30317996 –  May 19 '15 at 06:26
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78147/discussion-between-luke-and-stack-raja). – Luke May 19 '15 at 06:28