Sha256: 7f40a40370b0f10497659be1828b6dbd66b82bc5627256d286dfb0b9d502d91b

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

require 'libxml'
require 'pathname'
require 'cgi'

module OxMlk
  module XML
    Document = LibXML::XML::Document
    Node = LibXML::XML::Node
    Parser = LibXML::XML::Parser
    Error = LibXML::XML::Error
    
    class Node
      alias_method :value, :content
      
      def self.from(data)
        case data
        when XML::Document
          data.root
        when XML::Node
          data
        when File
          XML::Parser.io(data).parse.root
        when Pathname, URI
          XML::Parser.file(data.to_s).parse.root
        when String
          XML::Parser.string(data).parse.root
        else
          raise 'Invalid XML data'
        end
      end
      
      def self.build(name,nodes=[],attributes={})
        node = new(name)
        nodes.each {|n| node << n}
        attributes.each {|x| node[x.first.to_s] = x.last.to_s unless x.last.to_s.blank?}
        node
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oxmlk-0.2.3 lib/oxmlk/xml.rb
oxmlk-0.2.2 lib/oxmlk/xml.rb
oxmlk-0.2.1 lib/oxmlk/xml.rb