File: namespaces.rb

package info (click to toggle)
ruby-libxml 2.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,024 kB
  • ctags: 2,251
  • sloc: xml: 9,628; ansic: 8,409; ruby: 7,806; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# encoding: UTF-8

module LibXML
  module XML
    class Namespaces
      # call-seq:
      #   namespace.default -> XML::Namespace
      #
      # Returns the default namespace for this node or nil.
      #
      # Usage:
      #   doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
      #   ns = doc.root.namespaces.default_namespace
      #   assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
      def default
        find_by_prefix(nil)
      end

      # call-seq:
      #   namespace.default_prefix = "string"
      #
      # Assigns a name (prefix) to the default namespace.
      # This makes it much easier to perform XML::XPath
      # searches.
      #
      # Usage:
      #   doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
      #   doc.root.namespaces.default_prefix = 'soap'
      #   node = doc.root.find_first('soap:Envelope')
      def default_prefix=(prefix)
        # Find default prefix
        ns = find_by_prefix(nil)
        raise(ArgumentError, "No default namespace was found") unless ns
        Namespace.new(self.node, prefix, ns.href)
      end
    end
  end
end