我有一个来自 iSpring Solutions 的测验系统,它将 xml 结果数据发送到我的 php 脚本。我想提取信息以更新 mysql 数据库。
每个测验都有不同的问题,因此 xml 文件的长度/结构并不总是相同,但是我需要获取特定的数据。
这是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>
我需要 (a) 获取每个子节点的名称/id (b) 获取 id、状态、maxPoints 值 (c) 然后获取“方向”值
节点名称“matchingQuestion”或“fillInTheBlankQuestionEx”总是根据测验改变顺序。
我无法弄清楚如何获得这些值,因为每个测验的问题类型都不同!
提前谢谢了
约翰
完整的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>