-
Notifications
You must be signed in to change notification settings - Fork 17
Lesson: Handle Multiple Namespaces in a Terminology
flyingzumwalt edited this page Apr 11, 2013
·
1 revision
This information is incomplete.
DO NOT USE THIS TUTORIAL. IT'S INCORRECT AND INCOMPLETE
It's common to use more than one namespace in an XML document. In fact, that's the whole point of having namespaces. Let's pretend we want to have a datetime
term that creates ical:date-time nodes. This is totally abusing the ical schema, but the point here is just to show you how to handle multiple namespaces in one OM Terminology.
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", "xmlns:ical"=>"urn:ietf:params:xml:ns:icalendar-2.0")
t.datetime(:path=>"ical:date-time")
So the whole Terminology should look like this:
set_terminology do |t|
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", "xmlns:ical"=>"urn:ietf:params:xml:ns:icalendar-2.0")
t.datetime(:path=>"ical:date-time")
t.title {
t.language(:path=>{:attribute=>"lang"})
}
# The underscore is purely to avoid namespace conflicts.
t.name_ {
t.namePart
t.family_name(:path=>"namePart", :attributes=>{:type=>"family"})
t.given_name(:path=>"namePart", :attributes=>{:type=>"given"})
t.role {
t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
}
}
end
... reload the console, require fancy_book_metadata.rb, and create a new FancyBookMetaata called fancybook, then ...
fancybook.name.given_name = "Zoia"
=> "Zoia"
fancybook.name.family_name = "Horn"
=> "Horn"
fancybook.datetime = Time.now