[XML-SIG] Interested in feedback

Robin Becker robin@jessikat.co.uk
Tue, 27 Jun 2000 11:41:09 +0100


In article <Pine.LNX.4.21.0006262312300.25151-200000@loki.appliedtheory.com>, Benjamin Saller
<case@appliedtheory.com> writes
>
>I am not really sure how to prefix this. I have something that is while
>not general purpose does seem simple to use in the 80% case. If people
>disagree, or can think of things that might make this better I would like
>some feedback.
....
I like this a lot. I changed the parse method to

   def parse(self, fn):
        if type(fn) is StringType:
            self._parser.parseFile(open(fn))
        else:
            self._parser.parseFile(fn)
        return self._handler.object()
    
and added this to the bottom to make the module self testing. I would prefer
it if the name were all lower case as that makes life slightly more robust with win32.
if __name__=='__main__':
        dataset='''
        <container>
                <listen port="9000"/>
                         <container1>
                        <allow>
                                <host>loki.appliedtheory.com</host>
                        </allow>
                </container1>
                <container2>
                        <allow>
                                <host>127.0.0.1</host>
                                <host>foo.bar.com</host>
                                <host>baz.bar.com</host>
                        </allow>
                </container2>
                <container3>
                        <float>100.4123</float>
                        <numbers>
                                <int>8</int>
                                <int>16</int>
                                <int>32</int>
                        </numbers>
                </container3>
        </container>
        '''
        import xmlObjects, StringIO
        fp = StringIO.StringIO(dataset)

        p   = xmlObjects.Parser()
        xml = p.parse(fp)  # where maybe this should be a string or fp

        print xml.getValue("container1.allow.host")     # == 'loki'
        print xml.getValue("container2.allow.host[1]")  # == 'foo.bar.com'
        print xml.getValue("listen[port]", convert=int) # == 9000

        print xml.getValues("container2.allow.host") # == ['loki...', 'foo...' 'baz...']

        print xml.getXML() # does a decent job of reproducing the source
-- 
Robin Becker