Sha256: 8c0114789b7df48f35f453972074f6ea7e05eb21af7d053cbaa8490033fb2b0e

Contents?: true

Size: 1.55 KB

Versions: 6

Compression:

Stored size: 1.55 KB

Contents

# :stopdoc:
module Nokogiri
  module XML
    class DTD < Node
      def validate document
        error_list = []
        ctxt = LibXML.xmlNewValidCtxt

        LibXML.xmlSetStructuredErrorFunc(nil, SyntaxError.error_array_pusher(error_list))
        LibXML.xmlValidateDtd ctxt, document.cstruct, cstruct

        LibXML.xmlSetStructuredErrorFunc nil, nil

        LibXML.xmlFreeValidCtxt ctxt

        error_list
      end

      def system_id
        cstruct[:system_id]
      end

      def external_id
        cstruct[:external_id]
      end

      def elements
        internal_attributes :elements
      end

      def entities
        internal_attributes :entities
      end

      def attributes
        internal_attributes :attributes
      end

      def notations
        attr_ptr = cstruct[:notations]
        return nil if attr_ptr.null?

        ahash = {}
        proc = lambda do |payload, data, name|
          notation_cstruct = LibXML::XmlNotation.new(payload)
          ahash[name] = Notation.new(notation_cstruct[:name], notation_cstruct[:PublicID],
                                     notation_cstruct[:SystemID])
        end
        LibXML.xmlHashScan(attr_ptr, proc, nil)
        ahash
      end

      private

      def internal_attributes attr_name
        attr_ptr = cstruct[attr_name.to_sym]
        return nil if attr_ptr.null?

        ahash = {}
        proc = lambda do |payload, data, name|
          ahash[name] = Node.wrap(payload)
        end
        LibXML.xmlHashScan(attr_ptr, proc, nil)
        ahash
      end
    end
  end
end
# :startdoc:

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
superfeedr-nokogiri-1.4.0.20091116183308 lib/nokogiri/ffi/xml/dtd.rb
caring-nokogiri-1.4.1.pre1 lib/nokogiri/ffi/xml/dtd.rb
nokogiri-1.4.0-java lib/nokogiri/ffi/xml/dtd.rb
nokogiri-1.4.0-x86-mswin32 lib/nokogiri/ffi/xml/dtd.rb
nokogiri-1.4.0-x86-mingw32 lib/nokogiri/ffi/xml/dtd.rb
nokogiri-1.4.0 lib/nokogiri/ffi/xml/dtd.rb