Parse XML files


/ Published in: ActionScript 3
Save to your folder(s)

How to drill down to the content you need in an XML file.


Copy this code and paste it in your HTML
  1. Example XML code:
  2.  
  3. <question id = "a3" incorrectFeedBackID = "18190" correctFeedbackID = "18189">
  4. <answer id = "18183" isCorrect = "false"></answer>
  5. <answer id = "18184" isCorrect = "true"></answer>
  6. <answer id = "18185" isCorrect = "true"></answer>
  7. <answer id = "18186" isCorrect = "false"></answer>
  8. <answer id = "18187" isCorrect = "true"></answer>
  9. <answer id = "18188" isCorrect = "true"></answer>
  10. </question>
  11.  
  12. <question id = "a5" incorrectFeedBackID = "18199" correctFeedbackID = "18198">
  13. <answer id = "18192" isCorrect = "false"></answer>
  14. <answer id = "18193" isCorrect = "true"></answer>
  15. <answer id = "18194" isCorrect = "true"></answer>
  16. <answer id = "18195" isCorrect = "true"></answer>
  17. <answer id = "18196" isCorrect = "false"></answer>
  18. <answer id = "18197" isCorrect = "true"></answer>
  19. </question>
  20. ___________________________________________________________________
  21. To get the incorrectFeedBackID for a5:
  22.  
  23. trace("incorrectFeedBackID:", xml["question"][1].@incorrectFeedBackID);
  24. or
  25. trace(xml.question.(@id == "a5").@incorrectFeedBackID);
  26. ___________________________________________________________________
  27. To get the isCorrect value for 18193 in question a5:
  28.  
  29. trace("isCorrectValue:", xml["question"][1]["answer"][1].@isCorrect);
  30. or
  31. trace(xml.question.(@id == "a5").answer.(@id == "18193").@isCorrect);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.