pro mgffxmlparser::startElement, uri, local, name, attName, attValue
compile_opt strictarr
if (n_elements(*self.struct) eq 0L) then begin
if (n_elements(attName) eq 0L) then begin
atts = ''
endif else begin
for i = 0L, n_elements(attName) - 1L do begin
if (n_elements(atts) eq 0L) then begin
atts = create_struct(attName[i], attValue[i])
endif else begin
atts = create_struct(atts, attName[i], attValue[i])
endelse
endfor
endelse
*self.struct = create_struct(name, atts)
endif else begin
endelse
end
pro mgffxmlparser::endElement, uri, local, name
compile_opt strictarr
end
pro mgffxmlparser::characters, chars
compile_opt strictarr
end
function mgffxmlparser::getResult
compile_opt strictarr
return, *self.struct
end
pro mgffxmlparser::cleanup
compile_opt strictarr
self->idlffxmlsax::cleanup
ptr_free, self.struct
end
function mgffxmlparser::init, _extra=e
compile_opt strictarr
if (~self->idlffxmlsax::init(_extra=e)) then return, 0
self.struct = ptr_new(/allocate_heap)
return, 1
end
pro mgffxmlparser__define
compile_opt strictarr
define = { MGffXMLParser, inherits IDLffXMLSAX, $
currentPath: '', $
struct: ptr_new() $
}
end
function mg_xml_parse, input, url=url, xml_string=xmlString
compile_opt strictarr
parser = obj_new('MGffXMLParser')
parser->parseFile, input, url=url, xml_string=xmlString
result = parser->getResult()
obj_destroy, parser
return, result
end
url = 'http://brightkite.com/people/mgalloy.xml'
s = mg_xml_parse(url, /url)
mg_help, s
end