Module: Calligraphy::XML::Utils

Included in:
Lock, Propfind, Proppatch
Defined in:
lib/calligraphy/xml/utils.rb

Instance Method Summary collapse

Instance Method Details

#xml_for(body:, node:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/calligraphy/xml/utils.rb', line 3

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 n&.href == Calligraphy::DAV_NS && !n.prefix.nil?
  end
  namespace

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

  xml.css(node).children
end