diff --git a/lib/calligraphy.rb b/lib/calligraphy.rb index cd8fa1c..bbf7d8d 100644 --- a/lib/calligraphy.rb +++ b/lib/calligraphy.rb @@ -3,6 +3,8 @@ require 'calligraphy/web_dav_request' require 'calligraphy/xml/builder' require 'calligraphy/xml/namespace' require 'calligraphy/xml/node' +require 'calligraphy/xml/utils' module Calligraphy + DAV_NS = 'DAV:' end diff --git a/lib/calligraphy/xml/utils.rb b/lib/calligraphy/xml/utils.rb new file mode 100644 index 0000000..4fa6d3c --- /dev/null +++ b/lib/calligraphy/xml/utils.rb @@ -0,0 +1,18 @@ +module Calligraphy::XML + module Utils + 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 + end +end