module Calligraphy::XML::Utils

Miscellaneous XML convenience methods.

Public Instance Methods

xml_for(body:, node:) click to toggle source

Returns the XML for a given XML body and node/CSS selector.

# File lib/calligraphy/xml/utils.rb, line 8
def xml_for(body:, node:)
  xml = Nokogiri::XML body
  return :bad_request unless xml.errors.empty?

  namespace = nil
  xml.root.namespace_definitions.each do |n|
    namespace = "#{n.prefix}|" if dav_namespace n
  end

  node = node.split(' ').map! { |n| namespace + n }.join(' ') if namespace

  xml.css(node).children
end

Private Instance Methods

dav_namespace(namespace) click to toggle source
# File lib/calligraphy/xml/utils.rb, line 24
def dav_namespace(namespace)
  namespace&.href == Calligraphy::DAV_NS && !namespace.prefix.nil?
end