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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:57:24+00:00 2026-05-27T13:57:24+00:00

In django, addQuickElement(name,content,attr) generates XML like this <name attr=attr>content</name> While I want to generate

  • 0

In django,

addQuickElement(name,content,attr)

generates XML like this

<name attr="attr">content</name>

While I want to generate

<name attr="attr" />
  • 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-05-27T13:57:25+00:00Added an answer on May 27, 2026 at 1:57 pm

    Just don’t specify the contents argument.

    For reference, this is django/utils/xmlutils.py:

    """
    Utilities for XML generation/parsing.
    """
    
    from xml.sax.saxutils import XMLGenerator
    
    class SimplerXMLGenerator(XMLGenerator):
        def addQuickElement(self, name, contents=None, attrs=None):
            "Convenience method for adding an element with no children"
            if attrs is None: attrs = {}
            self.startElement(name, attrs)
            if contents is not None:
                self.characters(contents)
            self.endElement(name)
    

    You can see here that you just need to not specify contents, and so you can do x.addQuickElement(name, attrs=attrs).

    (A quick look at XMLGenerator indicates this will still produce an end-tag, rather than a self-closing tag. In Python 3.2 an argument short_empty_elements was added to XMLGenerator.__init__, but Django isn’t still only compatible with Python 2.x. If you care about getting short tags, take a look at the xml.sax.saxutils.XMLGenerator.startElement implementation.)

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

Sidebar

Related Questions

Django query gives me below output format,but i want below format data=`[{'total': 1744, 'name:
[Django 1.0.2] I have a view set up like this: (r'^redirect/(?P<object_id>\d+)/(?P<url>.*)/$', 'django.views.generic.simple.redirect_to', {'content_type': SiteType},
Django newbie here. I have two simple models like this: class Fluff(models.Model): # ....
django.forms is very nice, and does almost exactly what I want to do on
Django code samples involving post data often shows code similar to this: if request.method
Django's get_or_create function always cause get() returned more than one Model name error in
Django tutorials everywhere use constant-set application name all around - in urls file, in
Django objects aren't subscriptable meaning if you have user.name you can't define it with
Django 1.1.1 Models.py: class Datapoint(models.Model): parameter1 = models.FloatField() parameter2 = models.FloatField() I want to
Django documents give this example of associating extra data with a M2M relationship. Although

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.