Hello!
Excellent educational reply, thank you for that. But it does not fully solve my issue although I believe we are on the right path.
So the XML-file looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<assessmentItem xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/imscp_v1p1.xsd http://www.imsglobal.org/xsd/imsmd_v1p2 http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/imsqti_v2p1.xsd" identifier="item45790" title="MultipleChoice" adaptive="false" timeDependent="false" toolName="itslearning" toolVersion="3.3" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:qti="http://www.imsglobal.org/xsd/imsqti_v2p1">
<responseDeclaration cardinality="single" baseType="identifier" identifier="RESPONSE">
<correctResponse>
<value>A3</value>
</correctResponse>
<mapping lowerBound="-1" upperBound="1" defaultValue="0">
<mapEntry mapKey="A3" mappedValue="1" />
<mapEntry mapKey="A0" mappedValue="-0.33333333333333331" />
<mapEntry mapKey="A1" mappedValue="-0.33333333333333331" />
<mapEntry mapKey="A2" mappedValue="-0.33333333333333331" />
</mapping>
</responseDeclaration>
<outcomeDeclaration cardinality="single" baseType="identifier" identifier="FEEDBACK" view="" normalMaximum="0" normalMinimum="0" masteryValue="0" />
<outcomeDeclaration cardinality="single" baseType="identifier" identifier="INTEGRATEDFEEDBACK" view="" normalMaximum="0" normalMinimum="0" masteryValue="0" />
<itemBody>
<p>What is the capital of USA?</p>
<choiceInteraction responseIdentifier="RESPONSE" shuffle="false" maxChoices="1" minChoices="0">
<simpleChoice fixed="false" showHide="show" identifier="A0">
<p>Washington DC</p>
</simpleChoice>
<simpleChoice fixed="false" showHide="show" identifier="A1">
<p>Miami</p>
<p> </p>
</simpleChoice>
<simpleChoice fixed="false" showHide="show" identifier="A2">
<p>Los Angeles</p>
</simpleChoice>
<simpleChoice fixed="false" showHide="show" identifier="A3">
<p>New York</p>
</simpleChoice>
</choiceInteraction>
</itemBody>
<responseProcessing />
</assessmentItem>
Notice how the option Miami contains another <p>-tag but it's empty. I use now the following php code:
preg_match_all('/<p>(.{2,200}?)<\/p>/', utf8_decode($stream['data']), $ProcessedArray);
And when I print it out I do the following:
//Replace <p>-tags with <span>-tags for question headline
$patterns = array('<p>', '</p>');
$replacements = array('<span>', '</span>');
$FormalQuestion = str_replace($patterns, $replacements, $ProcessedArray[0][0]);
//Print question headline
echo '<strong>Fråga ' . $i . '. ' . $FormalQuestion . '</strong>' . "\n";
//Print question answers
echo $ProcessedArray[0][1] . "\n";
echo $ProcessedArray[0][2] . "\n";
echo $ProcessedArray[0][3] . "\n";
echo $ProcessedArray[0][4] . "\n";
However, the source code generates the following (another question):
Debatten omkring Rorschach's validitet kommer från tvetydiga resultat i forskning omkring:</span>
<p>Rorschachtestets prediktionsförmåga</p>
<p>Rorschachtestets förmåga att differentiera mellan olika kliniska grupper</p>
<p> </p></simpleChoice><simpleChoice fixed="false" showHide="show" identifier="A2"><p>Tolkningen av svaren i Rorschachtest</p>
<p> </p></simpleChoice><simpleChoice fixed="false" showHide="show" identifier="A3"><p>Alla ovanstående</p>
- Why does it include XML-code?
- How can we only extract <p>-tags in the XML that has content?