how to recover text from sequenceQuestion XML tag?
Author | Message |
I am stuck with getting the value from a XML element list. I wonder if someone here could help? Thanks in advance. Code: <sequenceQuestion status="correct" maxPoints="10" maxAttempts="1" awardedPoints="10" usedAttempts="1"> <direction>Order the following options</direction> <answers> <answer userDefinedPosition="0">Option 1</answer> <answer userDefinedPosition="1">Option 2</answer> <answer userDefinedPosition="2">Option 3</answer> <answer userDefinedPosition="3">Option 4</answer> <answer userDefinedPosition="4">Option 5</answer> </answers> </sequenceQuestion> And I need to print the elements in the tag. For example, I need to print "Option 1", "Option 2", ... , "Option 5" in a webpage by the order they were selected by the user. If i use this code: Code: $SequenceQuestionNumber = 1; foreach($answer_group->answers->answer as $userSequenceQuestion){ if($status!="notAnswered" && isset($userSequenceQuestion->attributes()->userDefinedPosition)) { $userDefinedPosition = (string)$userSequenceQuestion->attributes()->userDefinedPosition; $values .= "\"" . $userDefinedPosition . "\", "; I get as answer values "0", "1", "2", "3" and "4". But what I need is not the 'userDefinedPosition" but rather the text associated with it. For "0" I need to print "Option 1", for "1" I need "Option 2", for "3" I need "Option 2", etc... I have tried to build an array like this: Code: $answers = (array)$userSequenceQuestion->answer; $values .= "\"" . $answers[$userDefinedPosition] . "\", "; but I just get blanks (nothing) printed I guess what is messing my reference is the userDefinedPosition inside the tag, but I am not sure on how to get the labels instead of the index numbers. Any comments will be greatly appreciated. Thanks! JPMD
|
Thank you for your post!
|
||||
|
Who is online | |
---|---|
![]() |
In total there are 5 users online :: 1 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes) Most users ever online was 803 on Sat Dec 12, 2020 9:21 am Registered users: Bing [Bot] |