class XML::Mapping::ArrayNode
Node factory function synopsis:
array_node :_attrname_, _per_arrelement_path_ [, :default_value=>_obj_] [, :optional=>true] [, :class=>_c_] [, :marshaller=>_proc_] [, :unmarshaller=>_proc_] [, :mapping=>_m_] [, :sub_mapping=>_sm_]
-or-
array_node :_attrname_, _base_path_, _per_arrelement_path_ [keyword args the same]
Node that maps a sequence of sub-nodes of the XML tree to an attribute containing an array of Ruby objects, with each array element mapping to a corresponding member of the sequence of sub-nodes.
If base_path is not supplied, it is assumed to be “”.
base_path+"/"
+per_arrelement_path
is an XPath expression that must “yield” the sequence of XML nodes that is to be mapped to the array. The
difference between base_path and per_arrelement_path
becomes important when marshalling the array attribute back to XML. When that happens, base_path names
the most specific common parent node of all the mapped sub-nodes, and
per_arrelement_path names (relative to base_path) the
part of the path that is duplicated for each array element. For example,
with base_path=="foo/bar"
and
per_arrelement_path=="hi/ho"
, an array
[x,y,z]
will be written to an XML
structure that looks like this:
<foo> <bar> <hi> <ho> [marshalled object x] </ho> </hi> <hi> <ho> [marshalled object y] </ho> </hi> <hi> <ho> [marshalled object z] </ho> </hi> </bar> </foo>
Public Class Methods
Initializer. Called with keyword arguments and either 1 or 2 paths; the hindmost path argument passed is delegated to per_arrelement_path; the preceding path argument (if present, “” by default) is delegated to base_path.
# File lib/xml/mapping/standard_nodes.rb, line 270 def initialize(*args) path,path2,*args = super(*args) base_path,per_arrelement_path = if path2 [path,path2] else [".",path] end per_arrelement_path=per_arrelement_path[1..-1] if per_arrelement_path[0]==?/ @base_path = XML::XXPath.new(base_path) @per_arrelement_path = XML::XXPath.new(per_arrelement_path) @reader_path = XML::XXPath.new(base_path+"/"+per_arrelement_path) args end