Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8924573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:27:24+00:00 2026-06-15T07:27:24+00:00

I have a Solace JMS Messaging Box which I am automating the administration of,

  • 0

I have a Solace JMS Messaging Box which I am automating the administration of, and the device uses lots of very small XML posts to configure. Since the device has so very many commands in its XML spec, I need a way to create arbitrary XML requests.

The XML looks like:

<rpc semp-version="soltr/5_5">
<create>
<message-vpn>
<vpn-name>developer.testvpn</vpn-name>
</message-vpn>
</create>
</rpc>

And a second call to change a setting might look like this:

<rpc semp-version="soltr/5_5">
<message-vpn>
<vpn-name>developer.testvpn</vpn-name>
<export-policy>
<no>
<export-subscriptions/>
</no>
</export-policy>
</message-vpn>
</rpc>

Since there are many commands in the XML spec, I’m looking for a way to create them freely from something like dot name space. eg:

mycall = SolaceXML()
mycall.create.message_vpn.vpn_name="developer.testvpn"
mycall.message_vpn.vpn_name='developer.testvpn'
mycall.message_vpn.export_policy.no.export_subscription

UPDATE
I have posted my solution below. Its not as small as I’d like it but it works for me.

K

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:27:26+00:00Added an answer on June 15, 2026 at 7:27 am

    I have found a solution in the mean time. Hopefully this helps someone else. This solution builds nested dictionary objects from dot name space calls, and then converts it to XML.

    from xml.dom.minidom import Document
    import copy
    import re
    from collections import OrderedDict
    
    class d2x:
        ''' Converts Dictionary to XML '''
        def __init__(self, structure):
            self.doc = Document()
            if len(structure) == 1:
                rootName = str(structure.keys()[0])
                self.root = self.doc.createElement(rootName)
                self.doc.appendChild(self.root)
                self.build(self.root, structure[rootName])
    
        def build(self, father, structure):
            if type(structure) == dict:
                for k in structure:
                    tag = self.doc.createElement(k)
                    father.appendChild(tag)
                    self.build(tag, structure[k])
            elif type(structure) == OrderedDict:
                for k in structure:
                    tag = self.doc.createElement(k)
                    father.appendChild(tag)
                    self.build(tag, structure[k])
    
            elif type(structure) == list:
                grandFather = father.parentNode
                tagName = father.tagName
                grandFather.removeChild(father)
                for l in structure:
                    tag = self.doc.createElement(tagName)
                    self.build(tag, l)
                    grandFather.appendChild(tag)
    
            else:
                data = str(structure)
                tag = self.doc.createTextNode(data)
                father.appendChild(tag)
    
        def display(self):
            # I render from the root instead of doc to get rid of the XML header
            #return self.root.toprettyxml(indent="  ")
            return self.root.toxml()
    
    class SolaceNode:
        ''' a sub dictionary builder '''
        def __init__(self):
            self.__dict__ = OrderedDict()
        def __getattr__(self, name):
            name = re.sub("_", "-", name)
            try:
                return self.__dict__[name]
            except:
                self.__dict__[name] = SolaceNode()
                return self.__dict__[name]
        def __str__(self):
            return str(self.__dict__)
        def __repr__(self):
            return str(self.__dict__)
        def __call__(self, *args, **kwargs):
            return self.__dict__
        def __setattr__(self, name, value):
            name = re.sub("_", "-", name)
            self.__dict__[name] = value
    
    class SolaceXMLBuilder(object):
        ''' main dictionary builder
    
        Any dot-name-space like calling of a instance of SolaceXMLBuilder will create
        nested dictionary keys. These are converted to XML whenever the instance 
        representation is called ( __repr__ ) 
    
        Example
    
        a=SolaceXMLBuilder()
        a.foo.bar.baz=2
        str(a)
        '<rpc semp-version="soltr/5_5">\n<foo><bar><baz>2</baz></bar></foo></rpc>'
    
        '''
        def __init__(self):
            self.__dict__ = OrderedDict()
            self.__setattr__ = None
        def __getattr__(self, name):
            name = re.sub("_", "-", name)
            try:
                return self.__dict__[name]
            except:
                self.__dict__[name] = SolaceNode()
                return self.__dict__[name]
        def __repr__(self):
            # Show XML
            myxml = d2x(eval(str(self.__dict__)))
            # I had to conjur up my own header cause solace doesnt like </rpc> to have attribs
            #return str('<rpc semp-version="soltr/5_5">\n%s</rpc>' % myxml.display())
            return str('<rpc semp-version="soltr/5_5">\n%s</rpc>' % myxml.display())
        def __call__(self, *args, **kwargs):
            return self.__dict__
        # def __setattr__(self, name, value):
        #   raise Exception('no you cant create assignments here, only on sub-elements')
    
    
    
    if __name__ == '__main__':
        x = SolaceXMLBuilder()
        x.create.message_vpn.vpn_name='NEWVPN'
        print(x)
    
        # <?xml version="1.0" ?>
        # <rpc semp-version="soltr/5_5">
        #   <create>
        #     <message-vpn>
        #       <vpn-name>
        #         NEWVPN
        #       </vpn-name>
        #     </message-vpn>
        #   </create>
        # </rpc semp-version="soltr/5_5">   
    
        x=SolaceXMLBuilder()
        x.message_vpn.vpn_name='NEWVPN'
        x.message_vpn.no.feature_X
        print(x)
    
        # <?xml version="1.0" ?>
        # <rpc semp-version="soltr/5_5">
        #   <message-vpn>
        #     <vpn-name>
        #       NEWVPN
        #     </vpn-name>
        #     <no>
        #       <feature-X/>
        #     </no>
        #   </message-vpn>
        # </rpc semp-version="soltr/5_5">
    
    
        # >>> client = SolaceAPI('pt1')
        # >>> xml = SolaceXMLBuilder()
        # >>> xml.create.message_vpn.vpn_name='NEWVPN'
        # >>> client.rpc(str(xml))
        # {u'rpc-reply': {u'execute-result': {u'@code': u'ok'}, u'@semp-version': u'soltr/5_5'}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a text box which get data for price. If someone enter something like
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
have 2 questions : A computer with 32-bit address uses 2-level page table (9
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
have a help file which i have created in Notepad++ with the following syntax
Have an XML with next form: <categories someAttribute=test> <category id=1> <title></title> </category> <category id=1>
Have a bunch of classes which I need to do serialize and deserialize from/to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.