- Create a JavaScript class that converts an xml document into an object.
- Inspired from Ruby’s XmlSimple.
Created
April 30, 2009 20:01
-
-
Save ebot/104653 to your computer and use it in GitHub Desktop.
Ideas for Professor: JavaScript XML Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var course = new JsXml('course.xml'); | |
course.get('title'); // returns the title. | |
course.units[0].get('pages'); // returns the pages in the first unit | |
course.units[0].attributes.get('number'); // returns the attribute number | |
course.quiz.questions[0].get('answer'); //returns the answer to the first question |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<course> | |
<title>Peter's Test Course</title> | |
<version>v0001</version> | |
<author>Peter Frampton</author> | |
<copyrightyear>2009</copyrightyear> | |
<companyname>WorldWide Education USA</companyname> | |
<units> | |
<unit number="1"> | |
<title>Lesson 1</title> | |
<pages>3</pages> | |
<firstpagepath>/course/unit01/page01.htm</firstpagepath> | |
<graphic>/core/images/imageu01_01.jpg</graphic> | |
</unit> | |
<unit number="2"> | |
<title>Lesson 2</title> | |
<pages>3</pages> | |
<firstpagepath>/course/unit02/page01.htm</firstpagepath> | |
<graphic>/core/images/imageu02_01.jpg</graphic> | |
</unit> | |
</units> | |
<quiz> | |
<questions> | |
<question number="1"> | |
<text>What is the meaning of life?</text> | |
<answer>42</answer> | |
</question> | |
<questions> | |
</quiz> | |
</course> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment