×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    158

    Experience with SOAP?

    I'm thinking about using SOAP for my application, but therefore I need a SOAP processor. Anybody here that has successfully used SOAP messaging in their application?

  2. #2
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: Experience with SOAP?

    Quote Originally Posted by bercobeute
    I'm thinking about using SOAP for my application - -
    With full SOAP headers etc? What a waste of expensive bandwidth! :-)

    Quote Originally Posted by bercobeute
    but therefore I need a SOAP processor. Anybody here that has successfully used SOAP messaging in their application?
    I'm using sgmllib.py to parse simple XML-like dataformat. Data looks like this:
    Code:
    <img time='1156230837' id='79/94/000005215' sender='Aapo' title='Stikkaa vodaa'></img>
    And my parser returns a dictionary, where keys are tag names and values lists of dictionaries like this:
    Code:
    {'img': [[1156230837, {u'title': u'Stikkaa vodaa', u'sender': u'Aapo', u'id': u'79/94/000005215', u'time': u'1156230837'}], 
             [1156237022, {u'title': u'Hj l\xe4hettipy\xf6r\xe4', u'sender': u'Teemu', u'id': u'eb/cc/000005216', u'time': u'1156237022'}],
             ...
    {'msg': [[...
    Above is easy to use in Pys60 program later.

    If somebody is interested in this, I can post those few lines of Python code to this forum.

  3. #3
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: Experience with SOAP?

    Please post away, maybe someone is interested.

  4. #4
    Regular Contributor
    Join Date
    Sep 2005
    Location
    Finland, Helsinki
    Posts
    323

    Re: Experience with SOAP?

    Ok, here it goes. If copypaste to your editor does not work, try this temporary link:
    http://plok.in/tmp/PlokParser.py
    Just running it ("/path/to/python2.2 PlokParser.py") should show some results. If this does not work and you need more instructions how to test PlokParser, please reply to this thread. NOTE: sgmllib.py and markupbase.py are needed, but usually they are found by python if python installation is successful.

    Suggestions and improvements are appreciated.

    Code:
    # -*- coding: iso-8859-15 -*-
    # $Id: PlokParser.py 213 2006-08-23 19:26:18Z arista $
    # Copyright Aapo Rista and others 2006
    # License GPL
    
    import sgmllib
    import urllib
    import re
    
    class PlokParser(sgmllib.SGMLParser):
        """A simple parser class. See exampledata.xml for data details."""
    
        # Characters which will be encoded to entities
        chartable = {
           u'&':u'&amp;',
           u'"':u'&quot;',
    #       u"'":u"'", # This entity (single quote) went broken in nokia's forum-software
    # Try to replace second single quote with & #039; (without space inside)
           u'<':u'&lt;',
           u'>':u'&gt;',
        }
        # Entities which will be decoded to characters (see init)
        entitytable = {}
    
        def __init__(self, verbose=0):
            """Initialise an object, passing 'verbose' to the superclass."""
            sgmllib.SGMLParser.__init__(self, verbose)
            # This will hold parsed tags until parser is clear()'ed
            self.lists = {}
            # Construct entitytable by swapping keys and values in chartable
            for (key, value) in self.chartable.items():
                self.entitytable[value] = key
            charlist = self.chartable.keys()
            # re which matches all chars which must be entities in XML
            self.char_re = re.compile("[%s]" % ("".join(charlist)))
            # re which matches all possible entities you'd like to decode
            self.ent_re = re.compile(r'&.*?;')
    
        def parse(self, s):
            """Parse the given string 's'."""
            self.feed(s)
            self.close()
            
        def clear(self):
            """Empty all lists."""
            self.lists = {}
    
        def decode_entity(self, match):
            """Callback function for re.sub in unknown_starttag().
            Replaces entities found with character equivalent in entitytable."""
            entity = match.group()
            if self.entitytable.has_key(entity):
                return self.entitytable[entity]
            else: 
                return entity
    
        def encode_entity(self, match):
            """Callback function for re.sub in create_tag().
            Replaces characters found in chartable with entities."""
            char = match.group()
            if self.chartable.has_key(char):
                return self.chartable[char]
            else: 
                return char
    
        def unknown_starttag(self, tag, attrs):
            """Handles all tags and puts their attributes into the appropriate list.
            Decodes also html entities."""
            attr_dict = {}
            for i in range(0, len(attrs)):
                attr_dict[attrs[i][0]] = self.ent_re.sub(self.decode_entity, attrs[i][1])
            if attr_dict.has_key("time"):
                # I hope sortfield will not confuse folks too much
                # It is used to keep lists in order (see python's sort())
                sortfield = int(attr_dict["time"])
            else:
                sortfield = 0
            if len(attr_dict) > 0:
                if not self.lists.has_key(tag):
                    self.lists[tag] = []
                self.lists[tag].append([sortfield, attr_dict])
    
        def create_tag(self, tag, attr_dict):
            """Create XML-like tag including attributes found in attr_dict"""
            attr_list = []
            for k in attr_dict.keys():
                val = self.char_re.sub(self.encode_entity, attr_dict[k])
                attr_list.append(u'%s="%s"' % (k, val))
            return u"<%s %s></%s>" % (tag, " ".join(attr_list), tag)
            
    if __name__ == "__main__":
        import time
        # Initialize parser
        pp = PlokParser()
        # Populate tags-list
        tags1 = []
        tags1.append(pp.create_tag(u"img", {u"id":u"1234", u"name":u"foo.jpg", u"title":u"Mom & Dad"}))
        tags1.append(pp.create_tag(u"img", {u"id":u"42", u"name":u"bar.jpg", u"title":u"Mom's shoe"}))
        tags1.append(pp.create_tag(u"msg", {u"id":u"3187", u"sender":u"Aapo", u"text":u"Ugh"}))
        tags1.append(pp.create_tag(u"msg", {u"id":u"3188", u"sender":u"Teemu", u"text":u"<:->"}))
        # Create single xml-string from tags-list
        xml1 = u"\r\n".join(tags1)
        # Parse xml, parsed data will be found in dictionary pp.lists
        pp.parse(xml1)
        list1 = pp.lists.copy()
        tags2 = []
        for (tag, data) in list1.items():
            for i in range(len(data)):
                tags2.append(pp.create_tag(tag, data[i][1]))
        xml2 = u"\r\n".join(tags2)
        pp.clear()
        pp.parse(xml2)
        list2 = pp.lists.copy()
        print xml1
        print
        print list1
        print
        print xml2
        print
        print list2

Similar Threads

  1. OBEX and SOAP action for printer
    By NgocHai in forum Symbian
    Replies: 1
    Last Post: 2004-10-14, 03:46
  2. Project Manager with UI Project Experience
    By mattsankey in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-06-30, 09:33
  3. Project Managers with Symbian Project Experience
    By mattsankey in forum Symbian
    Replies: 0
    Last Post: 2004-06-30, 09:29
  4. SOAP RPC with MIDP 2.0 (Nokia 6230) ?
    By bluepuma in forum Mobile Java General
    Replies: 1
    Last Post: 2004-05-25, 16:51
  5. How to communicate between an MMSC and a SOAP server
    By dugla in forum General Messaging
    Replies: 0
    Last Post: 2003-11-15, 19:13

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×