-
Notifications
You must be signed in to change notification settings - Fork 16
Lesson: make terms that reference attributes on xml elements
jcoyne edited this page Oct 22, 2014
·
13 revisions
This Tutorial is known to work with om version 3.0.4.
Please update this wiki to reflect any other versions that have been tested.
- Define Terms in a Terminology that refer to XML attribute values rather than referring to the text within XML elements
Now say we want to use the xml:lang attribute to track the language encoding of the title and we want to have an OM Term called title_language
that lets us read and modify that attribute's value.
<fields>
<title lang="eng">ZOIA! Memoirs of Zoia Horn, Battler for the People's Right to Know.</title>
</fields>
Reopen fancy_book_metadata.rb
and add a language
nested inside the title
Term
t.title {
t.language(path: { attribute: "lang" })
}
Restart the console
bundle console
Require the FancyBookMetadata class definition.
require "./fancy_book_metadata"
fancybook = FancyBookMetadata.new
fancybook.title = "Zoia!"
=> "Zoia!"
fancybook.title.language = "eng"
puts fancybook.to_xml
<?xml version="1.0"?>
<fields>
<title lang="eng">Zoia!</title>
</fields>
=> nil
Go on to Lesson: Make Terms that reference XML elements with certain attribute values or return to the Tame your XML with OM page.