require 'win32ole-ext' module Msxml def Msxml.new return WIN32OLE.new_with_const('MSXML.DOMDocument', Msxml) end class ParseError < StandardError end def Msxml.handle_error(doc, url) error = doc.parseError if error.errorCode != 0 then docpos = "" if error.line != 0 then docpos = sprintf(":%d:%d", error.line, error.linepos) end msg = sprintf("\n%s%s: %s", url, docpos, error.reason.gsub(/\r/, "")) raise ParseError, msg end end def Msxml.open(url, preserveWhiteSpace = false, async = false) doc = new doc.preserveWhiteSpace = preserveWhiteSpace doc.async = async doc.load(url) begin handle_error(doc, url) rescue ParseError raise $!.type, $!.message, caller end return doc end end