Class: Nokogiri::XML::Document
- Inherits:
-
Object
- Object
- Nokogiri::XML::Document
- Defined in:
- lib/xml/smart.rb
Instance Method Summary collapse
- #custom_namespace_prefixes ⇒ Object
- #custom_namespace_prefixes_update ⇒ Object
- #ns_counter ⇒ Object
- #ns_update ⇒ Object
- #user_custom_namespace_prefixes ⇒ Object
- #user_custom_namespace_prefixes=(h) ⇒ Object
- #xpath_fast(path) ⇒ Object
Instance Method Details
#custom_namespace_prefixes ⇒ Object
61 62 63 |
# File 'lib/xml/smart.rb', line 61 def custom_namespace_prefixes @custom_namespace_prefixes || custom_namespace_prefixes_update end |
#custom_namespace_prefixes_update ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/xml/smart.rb', line 37 def custom_namespace_prefixes_update result = {} nsall = {} nsde = {} self.xpath('//namespace::*').each do |n| unless n.prefix == 'xml' nsde[n.href] = n.prefix if n.prefix.nil? nsall[n.href] = n.prefix end end count = -1 nsall.each do |k,v| if v.nil? && nsde.length == 1 result['xmlns'] = k elsif v.nil? && nsde.length > 1 result["xmlns#{count+=1}"] = k else result[v] = k end end @custom_namespace_prefixes = result end |
#ns_counter ⇒ Object
20 21 22 |
# File 'lib/xml/smart.rb', line 20 def ns_counter @ns_counter ||= 1 end |
#ns_update ⇒ Object
23 24 25 26 27 |
# File 'lib/xml/smart.rb', line 23 def ns_update @ns_counter ||= 1 @ns_counter += 1 self end |
#user_custom_namespace_prefixes ⇒ Object
64 65 66 |
# File 'lib/xml/smart.rb', line 64 def user_custom_namespace_prefixes @user_custom_namespace_prefixes ||= {} end |
#user_custom_namespace_prefixes=(h) ⇒ Object
67 68 69 |
# File 'lib/xml/smart.rb', line 67 def user_custom_namespace_prefixes=(h) @user_custom_namespace_prefixes = h end |
#xpath_fast(path) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/xml/smart.rb', line 29 def xpath_fast(path) ns = self.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes) ctx = XPathContext.new(self) ctx.register_namespaces(self.document.custom_namespace_prefixes.merge(self.document.user_custom_namespace_prefixes)) path = path.gsub(/xmlns:/, ' :') unless Nokogiri.uses_libxml? ctx.evaluate(path) end |