N
Nick da G
Hello, All.
I'm trying to consuming an xml file and map it to a Ruby object that
would describe that xml file.
What would be the best way to implement the following scenario.
Let's say I have several classes: Student, Course, Person, Tuition
Xml for this would look like this:
<Record>
<Student status="good">
<Person>
<Name>Alice</Name>
<BirthPlace>WonderLand</BirthPlace>
</Person>
<Course difficulty=">
<CourseName>Math III</CourseName>
<Grade>B+</Grade>
</Course>
<dt:Tuition>
<dt:Currency>USD</dt:Currency>
<dt:Amount>500</dt:Amount>
<dt
eriod>3 months</dt
eriod>
</dt:Tuition>
</Student>
</Record>
So basically I can parse the xml file using rexml and access all of my
xml tags and stuff.
Here is the Object I want to map it to:
class Student
@status
@person - access Person
end
class Person
end
class Course
end
class Tution
end
So the question is how do I access from class Student - class Person? So
that when I down the line later when I parse the file and do:
r = Record.new
I want to be able to do things like:
r.student.person.name
????
Thank you
I'm trying to consuming an xml file and map it to a Ruby object that
would describe that xml file.
What would be the best way to implement the following scenario.
Let's say I have several classes: Student, Course, Person, Tuition
Xml for this would look like this:
<Record>
<Student status="good">
<Person>
<Name>Alice</Name>
<BirthPlace>WonderLand</BirthPlace>
</Person>
<Course difficulty=">
<CourseName>Math III</CourseName>
<Grade>B+</Grade>
</Course>
<dt:Tuition>
<dt:Currency>USD</dt:Currency>
<dt:Amount>500</dt:Amount>
<dt
</dt:Tuition>
</Student>
</Record>
So basically I can parse the xml file using rexml and access all of my
xml tags and stuff.
Here is the Object I want to map it to:
class Student
@status
@person - access Person
end
class Person
end
class Course
end
class Tution
end
So the question is how do I access from class Student - class Person? So
that when I down the line later when I parse the file and do:
r = Record.new
I want to be able to do things like:
r.student.person.name
????
Thank you