I have a quiz system from iSpring Solutions that sends xml results data to my php script. I want to extract information to update a mysql database.
我有一个来自iSpring Solutions的测验系统,它将xml结果数据发送到我的php脚本。我想提取信息来更新mysql数据库。
Each quiz has different questions so the xml file is not always the same length/structure, however I need to get specific data.
每个测验都有不同的问题,因此xml文件的长度/结构并不总是相同,但我需要获取特定的数据。
Here is an extract from the xml file
这是xml文件的摘录
<questions>
<matchingQuestion id="{3F033905-566A-4B67-B7E4-324E4367FD16}" status="correct" maxPoints="2" maxAttempts="1" awardedPoints="2" usedAttempts="1">
<direction>Match the items on the left with the items on the right</direction>
</matchingQuestion>
<fillInTheBlankQuestionEx id="{6FCC5DAC-168F-4F44-87DF-9B1D162268D1}" status="partially" maxPoints="8" maxAttempts="1" awardedPoints="4" usedAttempts="1">
<direction>Which indefinite article should be written in front of the following words - 'a' or 'an'?</direction>
</fillInTheBlankQuestionEx>
</questions>
I need to (a) get the name/id of each child node (b) get the id, status, maxPoints values (c) then get the 'direction' value
我需要(a)获取每个子节点的名称/ id(b)获取id,status,maxPoints值(c)然后获取'direction'值
The node name 'matchingQuestion' or 'fillInTheBlankQuestionEx' always change order depending on the quiz.
节点名称“matchingQuestion”或“fillInTheBlankQuestionEx”始终根据测验更改顺序。
I can't figure out how to get these values as the question types vary for each quiz!
我无法弄清楚如何获得这些值,因为每个测验的问题类型各不相同!
Many thanks in advance
提前谢谢了
John
The full xml file is:
完整的xml文件是:
<quizReport xsi:schemaLocation="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults quizReport.xsd" version="1" xmlns="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<quizSettings quizType="graded" maxScore="10" maxNormalizedScore="100" timeLimit="180">
<passingPercent>0.8</passingPercent>
</quizSettings>
<summary score="2" percent="0.2" time="6">
<variables>
<variable name="VARIABLE_2" title="DFE number (7 digit)" value="2112377"/>
<variable name="USER_NAME" title="Your name" value="John"/>
<variable name="VARIABLE_1" title="Your class" value="6M"/>
</variables>
</summary>
<questions>
<matchingQuestion id="{3F033905-566A-4B67-B7E4-324E4367FD16}" status="correct" maxPoints="2" maxAttempts="1" awardedPoints="2" usedAttempts="1">
<direction>Match the items on the left with the items on the right</direction>
<premises>
<premise>an</premise>
<premise>a</premise>
</premises>
<responses>
<response>elephant</response>
<response>house</response>
</responses>
<matches>
<match premiseIndex="0" responseIndex="0"/>
<match premiseIndex="1" responseIndex="1"/>
</matches>
<userAnswer>
<match premiseIndex="0" responseIndex="0"/>
<match premiseIndex="1" responseIndex="1"/>
</userAnswer>
</matchingQuestion>
<fillInTheBlankQuestionEx id="{6FCC5DAC-168F-4F44-87DF-9B1D162268D1}" status="incorrect" maxPoints="8" maxAttempts="1" awardedPoints="0" usedAttempts="1">
<direction>Which indefinite article should be written in front of the following words - 'a' or 'an'?</direction>
<details>
<blank userAnswer="" correct="false">
<answer>a</answer>
<answer>a</answer>
</blank>
<text><![CDATA[ television
]]></text>
<blank userAnswer="" correct="false">
<answer>a</answer>
</blank>
<text><![CDATA[ boy
]]></text>
<blank userAnswer="" correct="false">
<answer>an</answer>
</blank>
<text><![CDATA[ umbrella
]]></text>
<blank userAnswer="" correct="false">
<answer>a</answer>
</blank>
<text><![CDATA[ house
]]></text>
<blank userAnswer="" correct="false">
<answer>an</answer>
</blank>
<text><![CDATA[ hour
]]></text>
<blank userAnswer="" correct="false">
<answer>an</answer>
</blank>
<text><![CDATA[ igloo
]]></text>
<blank userAnswer="" correct="false">
<answer>a</answer>
</blank>
<text><![CDATA[ minute
]]></text>
<blank userAnswer="" correct="false">
<answer>an</answer>
</blank>
<text><![CDATA[ elephant]]></text>
</details>
</fillInTheBlankQuestionEx>
</questions>
</quizReport>
2 个解决方案
#1
0
To begin your codding, i show an example. Suppose, $text contains xml
为了开始你的编码,我举了一个例子。假设,$ text包含xml
$xml = new SimpleXMLElement($text);
echo '<pre>';
foreach ($xml->questions->children() as $q) {
// print_r($q); echo '<br/>';
print_r((string)$q->getName());echo '<br/>';
print_r((string)$q->attributes()->id);echo '<br/>';
print_r((string)$q->direction);echo '<br/>';
}
result:
matchingQuestion
{3F033905-566A-4B67-B7E4-324E4367FD16}
Match the items on the left with the items on the right
fillInTheBlankQuestionEx
{6FCC5DAC-168F-4F44-87DF-9B1D162268D1}
Which indefinite article should be written in front of the following words - 'a' or 'an'?
#2
0
Thank you for your reply, I used the code below, from Splash58 to re-write the php that is updating a mysql database:
谢谢你的回复,我使用下面的代码,从Splash58重新编写更新mysql数据库的php:
foreach ($xml->questions->children() as $q) {
$QuestionType=(string)$q->getName();
$QuestionUUID=(string)$q->attributes()->id;
$QuestionAsked=(string)$q->direction;
$query="INSERT INTO questions (UUID, Qtype, Question) VALUES ('".$QuestionUUID."', '".$QuestionType."', '".$QuestionAsked."')";
$mysqli->query($query);
}
However, only the first question is being added to the DB.
但是,只有第一个问题被添加到数据库中。
#1
0
To begin your codding, i show an example. Suppose, $text contains xml
为了开始你的编码,我举了一个例子。假设,$ text包含xml
$xml = new SimpleXMLElement($text);
echo '<pre>';
foreach ($xml->questions->children() as $q) {
// print_r($q); echo '<br/>';
print_r((string)$q->getName());echo '<br/>';
print_r((string)$q->attributes()->id);echo '<br/>';
print_r((string)$q->direction);echo '<br/>';
}
result:
matchingQuestion
{3F033905-566A-4B67-B7E4-324E4367FD16}
Match the items on the left with the items on the right
fillInTheBlankQuestionEx
{6FCC5DAC-168F-4F44-87DF-9B1D162268D1}
Which indefinite article should be written in front of the following words - 'a' or 'an'?
#2
0
Thank you for your reply, I used the code below, from Splash58 to re-write the php that is updating a mysql database:
谢谢你的回复,我使用下面的代码,从Splash58重新编写更新mysql数据库的php:
foreach ($xml->questions->children() as $q) {
$QuestionType=(string)$q->getName();
$QuestionUUID=(string)$q->attributes()->id;
$QuestionAsked=(string)$q->direction;
$query="INSERT INTO questions (UUID, Qtype, Question) VALUES ('".$QuestionUUID."', '".$QuestionType."', '".$QuestionAsked."')";
$mysqli->query($query);
}
However, only the first question is being added to the DB.
但是,只有第一个问题被添加到数据库中。