Author Message

Posted: Tue May 10, 2016 11:30 pm   Post subject: how to recover text from sequenceQuestion XML tag?

I am stuck with getting the value from a XML element list. I wonder if someone here could help? Thanks in advance.

Here is the problem. I have this XML element:

<sequenceQuestion status="correct" maxPoints="10" maxAttempts="1" awardedPoints="10" usedAttempts="1">
  <direction>Order the following options</direction>
    <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>

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:

$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:
$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!

Profile profile test

Posted: Wed May 11, 2016 8:20 am   Post subject: Re: how to recover text from sequenceQuestion XML tag?

Thank you for your post!

Let me suggest that you take a look at this article on how to send quiz results to server: ... erver.html

Also, here is a sample PHP script for server to parse quiz results:

Also, here is another topic on a similar question:

Hope you find this information helpful!

Profile profile test
Display posts from previous:  Sort by  


Who is online
Who is online In total there are 12 users online :: 1 registered, 0 hidden and 11 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: Google [Bot]