module Representable::XML
Public Class Methods
Source
# File lib/representable/xml.rb, line 12 def self.included(base) base.class_eval do include Representable extend ClassMethods self.representation_wrap = true # let representable compute it. register_feature Representable::XML end end
Public Instance Methods
Source
# File lib/representable/xml/binding.rb, line 5 def Node(document, name, attributes={}) node = Nokogiri::XML::Node.new(name.to_s, document) # Java::OrgW3cDom::DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces. attributes.each { |k, v| node[k] = v } # TODO: benchmark. node end
Source
# File lib/representable/xml.rb, line 42 def from_node(node, options={}) update_properties_from(node, options, Binding) end
Source
# File lib/representable/xml.rb, line 36 def from_xml(doc, *args) node = parse_xml(doc, *args) from_node(node, *args) end
Also aliased as: parse
Source
# File lib/representable/xml.rb, line 47 def to_node(options={}) options[:doc] = Nokogiri::XML::Document.new # DISCUSS: why do we need a fresh Document here? root_tag = options[:wrap] || representation_wrap(options) create_representation_with(Node(options[:doc], root_tag.to_s), options, Binding) end
Returns a Nokogiri::XML object representing this object.
Source
# File lib/representable/xml.rb, line 54 def to_xml(*args) to_node(*args).to_s end
Also aliased as: render
Private Instance Methods
Source
# File lib/representable/xml.rb, line 67 def parse_xml(doc, *args) node = Nokogiri::XML(doc) node.remove_namespaces! if remove_namespaces? node.root end
Source
# File lib/representable/xml.rb, line 62 def remove_namespaces? # TODO: make local Config easily extendable so you get Config#remove_ns? etc. representable_attrs.options[:remove_namespaces] end