module Representable::XML

Public Class Methods

included(base) click to toggle 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

Node(document, name, attributes={}) click to toggle 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
from_node(node, options={}) click to toggle source
# File lib/representable/xml.rb, line 42
def from_node(node, options={})
  update_properties_from(node, options, Binding)
end
from_xml(doc, *args) click to toggle 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
parse(doc, *args)
Alias for: from_xml
render(*args)
Alias for: to_xml
to_node(options={}) click to toggle source

Returns a Nokogiri::XML object representing this object.

# 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
to_xml(*args) click to toggle 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

parse_xml(doc, *args) click to toggle 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
remove_namespaces?() click to toggle 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