Mam problemy z pobraniem danych w elemencie potomnym <questions> sekcja CDATA. Są tam 4 pytania oraz odpowiedzi, które chciałbym wyodrębnić i finalnie wysłać do bazy.
Korzystając z DOM (kod niżej)
$dom = new DOMDocument(); $dom->load('wynik.xml'); $dom->preserveWhiteSpace = false; $dana = $dom->getElementsByTagName('questions'); foreach ($dana as $i) { }
otrzymuje
Kod
Pytanie1Odpowiedz1Odpowiedz2Odpowiedz3Pytanie4Odp1Odp2Odp3Pytanie3PrawdaFałszPyt
anie2Multi_odp1Multi_odp2Multi_odp3Multi_odp4
anie2Multi_odp1Multi_odp2Multi_odp3Multi_odp4
Czy ktoś mógłby mnie naprowadzić jak powinna wyglądać składnia aby uzyskać to o co pytam?
Plik xml ma postać:
<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><quizSettings quizType="graded" maxScore="100" maxNormalizedScore="100" timeLimit="1200"><passingPercent>70</passingPercent></quizSettings><summary score="50" percent="50" time="9" finishTimestamp="1 kwietnia 2022 13:41" passed="false"><variables><variable name="USER_NAME" title="login" value="xyz"/></variables></summary><questions><multipleChoiceQuestion id="j2vzvoypej24" status="correct" evaluationEnabled="true" maxPoints="25" maxAttempts="1" awardedPoints="25" usedAttempts="1"><direction><text><![CDATA[Pytanie1]]></text></direction><answers correctAnswerIndex="0" userAnswerIndex="0"><answer><text><![CDATA[Odpowiedz1]]></text></answer><answer><text><![CDATA[Odpowiedz2]]></text></answer><answer><text><![CDATA[Odpowiedz3]]></text></answer></answers></multipleChoiceQuestion><multipleChoiceQuestion id="k5afxylfcy93" status="incorrect" evaluationEnabled="true" maxPoints="25" maxAttempts="1" awardedPoints="0" usedAttempts="1"><direction><text><![CDATA[Pytanie4]]></text></direction><answers correctAnswerIndex="1" userAnswerIndex="2"><answer><text><![CDATA[Odp1]]></text></answer><answer><text><![CDATA[Odp2]]></text></answer><answer><text><![CDATA[Odp3]]></text></answer></answers></multipleChoiceQuestion><trueFalseQuestion id="lvyggjalsr9g-jn6ftz1phcoo" status="correct" evaluationEnabled="true" maxPoints="25" maxAttempts="1" awardedPoints="25" usedAttempts="1"><direction><text><![CDATA[Pytanie3]]></text></direction><answers correctAnswerIndex="0" userAnswerIndex="0"><answer><text><![CDATA[Prawda]]></text></answer><answer><text><![CDATA[Fałsz]]></text></answer></answers></trueFalseQuestion><multipleResponseQuestion id="yqb2r4lrnqz8" status="incorrect" evaluationEnabled="true" maxPoints="25" maxAttempts="1" awardedPoints="0" usedAttempts="1"><direction><text><![CDATA[Pytanie2]]></text></direction><answers><answer correct="true" selected="false"><text><![CDATA[Multi_odp1]]></text></answer><answer correct="true" selected="true"><text><![CDATA[Multi_odp2]]></text></answer><answer correct="true" selected="true"><text><![CDATA[Multi_odp3]]></text></answer><answer correct="true" selected="false"><text><![CDATA[Multi_odp4]]></text></answer></answers></multipleResponseQuestion></questions></quiz>