Add XML::Utils module

This commit is contained in:
Brandon Robins
2017-10-23 21:10:24 -05:00
parent e64cb55c5d
commit 5858f93c0d
2 changed files with 20 additions and 0 deletions

View File

@@ -3,6 +3,8 @@ require 'calligraphy/web_dav_request'
require 'calligraphy/xml/builder' require 'calligraphy/xml/builder'
require 'calligraphy/xml/namespace' require 'calligraphy/xml/namespace'
require 'calligraphy/xml/node' require 'calligraphy/xml/node'
require 'calligraphy/xml/utils'
module Calligraphy module Calligraphy
DAV_NS = 'DAV:'
end end

View File

@@ -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