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 8469639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:17:01+00:00 2026-06-10T16:17:01+00:00

I am trying to open an xml file, manipulate and render to response or

  • 0

I am trying to open an xml file, manipulate and render to response or download file from url. I am doing to return multiple objects, when I say print after for loop, in terminal I see every requested objects comes but when I say return only single object comes both to requested url and to terminal.Here is my code;

def xml(request):
filename = "/usr/..../...."  
programs = x.objects.all()
categories = y.objects.all()

with open(filename,'r+') as f:  

    old = f.read()
    for m,k in itertools.product(categories,programs):
        if k.name_tr == m.name_tr:
            s = old.replace ('titlesss',k.name_tr,1) 
            j= k.introduction_tr
            decoded = BeautifulStoneSoup(j, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
            x =str(decoded)
            x = unicode(x,"utf-8")
            s = s.replace ("infosss",x,1)
            if  m.id == 310:
                    s = s.replace('idsss',"231",1)
            elif m.id == 308:
                    s = s.replace ('idsss',"230",1)
            elif m.id == 159:
                    s = s.replace ('idsss',"203",1)
            elif m.id == 163:
                    s = s.replace ('idsss',"204",1)
            elif m.id == 280:
                    s = s.replace ('idsss',"212",1)
            elif m.id == 157:
                    s = s.replace ('idsss',"202",1)
            elif m.id == 282:
                    s = s.replace ('idsss',"211",1)
            response = HttpResponse(s,mimetype ="application/force-download")                                                       
            response['Content-Disposition'] = 'attachment; filename=output.xml'
            return response
  • 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-10T16:17:02+00:00Added an answer on June 10, 2026 at 4:17 pm

    Once a function ‘returns’ it terminates. Therefore, your for loop only executes once. You might want to replace the ‘return’ with an ‘yield’, thus your function becoming a generator that yields a response at each iteration of the for loop.

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

Sidebar

Related Questions

I want to parse an XML file from URL using JDOM. But when trying
I'm trying to open an xml file in the current location of the executable
I'm trying to open up an xml file to parse it, but I am
I'm trying to use Nokogiri to grab some data from an XML file, then
I am trying to open and read a xml file as a local resource
I'm trying to retrieve information from an online XML file and it takes too
I am trying to extract data from a xml file, get rid of the
I'm trying to open/load an XML file specified in an Excel worksheet in the
I'm trying to open XML file, add some changes, and save to other XML
I'm trying to open a file with this: document = builder.parse(new File(Data.xml)); and I'm

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.