lib/om/xml/dynamic_node.rb in om-1.4.2 vs lib/om/xml/dynamic_node.rb in om-1.4.3
- old
+ new
@@ -1,30 +1,32 @@
module OM
module XML
#
# Provides a natural syntax for using OM Terminologies to access values from xml Documents
+ #
+ # *Note*: All of these examples assume that @article is an instance of OM::Samples::ModsArticle. Look at that file to see the Terminology.
#
# @example Return an array of the value(s) "start page" node(s) from the second issue node within the first journal node
# # Using DynamicNode syntax:
# @article.journal(0).issue(1).pages.start
# # Other ways to perform this query:
# @article.find_by_terms({:journal => 0}, {:issue => 1}, :pages, :start)
- # @article.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:part[2]/extent[@unit="pages"]")
+ # @article.ng_xml.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:part[2]/extent[@unit="pages"]", {"oxns"=>"http://www.loc.gov/mods/v3"})
#
# @example Return an NodeSet of the _first titles_ of all journal nodes
# # Using DynamicNode syntax:
# @article.journal.title(1)
# # Other ways to perform this query:
# @article.find_by_terms(:journal, {:title => 1})
- # @article.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title[1]")
+ # @article.ng_xml.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title[1]", {"oxns"=>"http://www.loc.gov/mods/v3"})
#
# @example Find all of the titles from all journals & return the first title Node from that NodeSet
# # Using DynamicNode syntax:
# @article.journal.title[1]
# # Other ways to perform this query:
# @article.find_by_terms(:journal, :title)[1]
- # @article.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title")[1]
+ # @article.ng_xml.xpath("//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title", {"oxns"=>"http://www.loc.gov/mods/v3"})[1]
#
class DynamicNode
attr_accessor :key, :index, :parent, :addressed_node, :term
def initialize(key, index, document, term, parent=nil) ##TODO a real term object in here would make it easier to lookup
self.key = key
@@ -71,10 +73,12 @@
@document.term_values_append(:parent_select=> parent.to_pointer,:parent_index=>0,:template=>to_pointer,:values=>z)
else
@document.term_value_update(xpath, y.to_i, z)
end
end
- @document.dirty = true
+ if @document.respond_to?(:dirty=)
+ @document.dirty = true
+ end
end
def sanitize_new_values(new_values)
# Sanitize new_values to always be a hash with indexes
case new_values