Skip to content

Instantly share code, notes, and snippets.

@flavorjones
Created February 6, 2009 07:06
Show Gist options
  • Save flavorjones/59266 to your computer and use it in GitHub Desktop.
Save flavorjones/59266 to your computer and use it in GitHub Desktop.
require 'ffi'
module Nokogiri
module LibXML
extend FFI::Library
ffi_lib "/usr/lib/libxml2.so"
callback :start_document_sax_func, [:pointer], :void
callback :end_document_sax_func, [:pointer], :void
callback :start_element_sax_func, [:pointer, :string, :pointer], :void
callback :end_element_sax_func, [:pointer, :string], :void
callback :characters_sax_func, [:pointer, :string, :int], :void
callback :comment_sax_func, [:pointer, :string], :void
callback :warning_sax_func, [:pointer, :string], :void
callback :error_sax_func, [:pointer, :string], :void
callback :cdata_block_sax_func, [:pointer, :string, :int], :void
attach_function :xmlSAXUserParseMemory, [:pointer, :pointer, :pointer, :int], :int
attach_function :xmlSAXUserParseFile, [:pointer, :pointer, :string], :int
attach_function :xmlParseDocument, [:pointer], :int
attach_function :xmlFreeParserCtxt, [:pointer], :void
attach_function :htmlSAXParseFile, [:pointer, :pointer, :pointer, :pointer], :pointer
attach_function :htmlSAXParseDoc, [:pointer, :pointer, :pointer, :pointer], :pointer
end
end
module Nokogiri
module LibXML
class XmlSaxHandler < FFI::ManagedStruct
layout(:internalSubset, :pointer,
:isStandalone, :pointer,
:hasInternalSubset, :pointer,
:hasExternalSubset, :pointer,
:resolveEntity, :pointer,
:getEntity, :pointer,
:entityDecl, :pointer,
:notationDecl, :pointer,
:attributeDecl, :pointer,
:elementDecl, :pointer,
:unparsedEntityDecl, :pointer,
:setDocumentLocator, :pointer,
:startDocument, :start_document_sax_func,
:endDocument, :end_document_sax_func ,
:startElement, :start_element_sax_func,
:endElement, :end_element_sax_func,
:reference, :pointer,
:characters, :characters_sax_func,
:ignorableWhitespace, :pointer,
:processingInstruction, :pointer,
:comment, :comment_sax_func,
:warning, :warning_sax_func,
:error, :error_sax_func,
:fatalError, :pointer,
:getParameterEntity, :pointer,
:cdataBlock, :cdata_block_sax_func,
:externalSubset, :pointer,
:initialized, :uint
)
def self.allocate
new LibXML.calloc(1, LibXML::XmlSaxHandler.size)
end
def self.release ptr
LibXML.free(ptr)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment