# $id$ @load xml-init @load xml module XML; redef check_for_unused_event_handlers = F; const ia_doc_dir = "itms_amazon_documents"; const ia_nr_doc_store = 9999; global ia_doc_stored: table[string] of count &default = 0; function ia_get_elt_name(name: string, uri: string): string { if ( uri != "" ) return fmt("\"%s\":%s", uri, name); else return name; } event xml_document(c: connection, doc_elt: string, namesp: string, doc: string) { if ( strstr( namesp, "http://webservices.amazon.com/AWSECommerceService" ) == 0 && strstr( namesp, "http://www.apple.com/itms" ) == 0 ) return; local full_name = ia_get_elt_name(doc_elt, namesp); local doc_no = ia_doc_stored[full_name]; if ( doc_no < ia_nr_doc_store ) { mkdir(ia_doc_dir); local doc_file = open( fmt("%s/%s-%d.xml", ia_doc_dir, doc_elt, doc_no) ); print doc_file, doc; close( doc_file ); ++ia_doc_stored[full_name]; } }