:PHPを使用して別のノード値に従ってXML内の特定のノードを取得する方法は?私は、このサンプルのようなXMLで動作するようにしようとしています
<?xml version="1.0"?>
<quizReport version="1" xsi:schemaLocation="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults quizReport.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ispringsolutions.com/ispring/quizbuilder/quizresults">
<quizSettings timeLimit="0" maxNormalizedScore="100" maxScore="20" quizType="graded">
<passingPercent>0.6</passingPercent>
</quizSettings>
<summary time="4" percent="0.5" score="10">
<variables>
<variable title="Nom" value="test1411" name="USER_NAME"/>
<variable title="Courriel" value="" name="USER_EMAIL"/>
</variables>
</summary>
<questions>
<trueFalseQuestion usedAttempts="1" awardedPoints="10" maxAttempts="1" maxPoints="10" status="correct" id="{11AD6662-ACF3-4C2B-A3E6-04311C0DD8DB}">
<direction>Le mot de passe de votre compte iNews est indépendant de votre mot de passe radiocanadien géré par ActiveDirectory. </direction>
<answers userAnswerIndex="0" correctAnswerIndex="0">
<answer>Vrai </answer>
<answer>Faux </answer>
</answers>
</trueFalseQuestion>
<trueFalseQuestion usedAttempts="1" awardedPoints="0" maxAttempts="1" maxPoints="10" status="incorrect" id="{F13CF7F1-C830-41AF-A54C-CE78EE383611}">
<direction>Le protocole FTP permet de reprendre un transfert de fichier qui a été arrêté, sans recommencer le transfert depuis le début. </direction>
<answers userAnswerIndex="1" correctAnswerIndex="0">
<answer>Vrai </answer>
<answer>Faux </answer>
</answers>
</trueFalseQuestion>
</questions>
</quizReport>
それぞれの質問には、例えば、ID属性を持っています{11AD6662-ACF3-4C2B-A3E6-04311C0DD8DB}。 質問のステータスがテキストとして返されます(つまり、が正しいまたはが正しくありません。)。
私の目標は、各質問のステータスを抽出し、同じ質問IDで列がラベル付けされているデータベースに入れます(私はMySQL INSERTに慣れています)。
私は多くのソリューション(xPath、foreach ...)を試しましたが、動作するコードを取得できません。すべての努力は、SimpleXMLElementを使用して行われました。
したがって、終了時に、私は質問IDで標識された列の下正しい又は誤っ DBに値を挿入する(例えば、{11AD6662-ACF3-4C2B-A3E6-04311C0DD8DB})毎XMLの1つの質問(最大100の質問を含むことができる)。だからXMLを介していくつかの種類のループが必要です。
タグ名truFalseQuestionは、質問のタイプによって異なる場合があります(別の質問が複数の選択肢があるなど)。私はこの単純なXMLをステップバイステップで理解できるようにしました。
* {11AD6662-ACF3-4C2B-A3E6-04311C0DD8DB}というラベルの列の下に* ... MySQLがそのようなフィールド名を許可するのではないかと疑います。あなたはおそらく* questionid *とこれを値として別のフィールドを意味していました。 – Parfait
このアプローチでは、可能性のある質問タグ名を一覧表示するためにメタデータを追加する必要があるようです。 – bassxzero