source: products/qPloneGoogleSitemaps/trunk/tests/XMLParser.py @ 727

Last change on this file since 727 was 1, checked in by myroslav, 14 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 613 bytes
Line 
1from xml.parsers.expat import ParserCreate
2import re
3
4def parse(data):
5    def start_el(name, attrs):
6        ParsedXML['start'][name] = attrs
7
8    def char_handler(data):
9        patt = re.compile('\S+', re.UNICODE)
10        if patt.search(data):
11            ParsedXML['data'].append(data)
12
13    ParsedXML = {'start':{}, 'end':[], 'data':[]}
14    parser = ParserCreate()
15    parser.StartElementHandler = start_el
16    parser.CharacterDataHandler = char_handler
17    parser.Parse(data)
18    return ParsedXML
19
20def hasURL(xml, url):
21    parsed_sitemap = parse(xml)
22    data = parsed_sitemap['data']
23    return url in data
Note: See TracBrowser for help on using the repository browser.