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

  • Home
  • SEARCH
  • 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 9190865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:33:28+00:00 2026-06-17T20:33:28+00:00

I would like to generate specific xml strings from my module, based on the

  • 0

I would like to generate specific xml strings from my module, based on the type of msg requested by some code using my module. Each of these xml strings contains some data that gets generated dynamically. For example, many of these xml string have a cookie field that is generated using another function.

I started out with a python dictionary that initializes all the xml strings with the dynamic field (ie cookie) pre-populated (ie, not exactly dynamic). And then I call the dictionary to get the relevant xml strings.

The problem with this approach is that the cookies expire every hour and therefore the strings being returned by the module after an hour have those expired values. What I would ideally like to have is some form of a generator function (not sure if that’s even possible in this case) that returns the correctly formed strings as and when they are requested based on the msg_type requested (as in the example below). Each of the xml strings saved in this dict is in a unique format, so I can’t exactly have some sort of a common template xml generator.

As an example, the dict that I have defined looks similar to get_msg dictionary here:

        get_msg["msg_value_1"] = """<ABC cookie=""" + getCookie() + """ > 
                                         <XYZ """ + foo_name +""">
                                         </XYZ>
                                  </ABC>"""

        get_msg["msg_value_2"] = """<ABC cookie=""" + getCookie() + """ > 
                                         <some text """ + bar_name + """>
                                         </XYZ>
                                  </ABC>"""

What would be a good approach to be able to generate these xml strings on the fly with getCookie() getting invoked for every fresh msg request (not necessarily using dictionaries). Any input would be appreciated.

  • 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-17T20:33:29+00:00Added an answer on June 17, 2026 at 8:33 pm

    For this I would create a class that is as such

    class SF( object ):
        def __init__( self, temp, args ):
                self.temp = temp
                self.args = args
    
        def __call__( self ):
                ret = self.temp
                for k, v in self.args.iteritems():
                        if hasattr( v, "__call__" ):
                                v = v()
                        ret = ret.replace( "{%s}" % k, str( v ) )
                return ret
    
    s = SF( "This is a {test} with another {value}", 
            { "test": lambda: 100, "value": "Test" } )
    
    print s()
    
    This is a 100 with another Test
    

    This will allow you to pass in various templates and each part that you need to replace you will have {cookie} with the name wrapped with curly brackets. These SF objects can then be stored into your dictionary and then simply called to returned your respective XML.

    I also highly recommend using a XML library such as lxml or something similar to produce correct XML when things get more complicated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a function that I would like to generate random strings from
I would like to generate a patch with all commits from a local branch.
I would like to generate POJO, XML for a given database. Database: ( contents
i would like to generate a very simple report with some images and text
I would like to generate the mysql-password hash from js. I know the method
I have a specific case here in which I would like some security advice.
I am trying to generate an xml document in a specific format. I would
I am using bootstrap-dropdown to generate a Dropdown menu. I would like to disable
I would like to use ZXing to generate QR code and show it on
I would like to ignore a specific named sub-folder from all current and future

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.