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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:02:13+00:00 2026-06-15T16:02:13+00:00

I am generating an SVG file that’s intended to include Inkscape-specific tags. For example,

  • 0

I am generating an SVG file that’s intended to include Inkscape-specific tags. For example, inkscape:label and inkscape:groupmode. I am using lxml etree as my parser/generator. I’d like to add the label and groupmode tags to the following instance:

layer = etree.SubElement(svg_instance, 'g', id="layer-id")

My question is how do I achieve that in order to get the correct output form in the SVG, for example:

<g inkscape:groupmode="layer" id="layer-id" inkscape:label="layer-label">
  • 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-15T16:02:14+00:00Added an answer on June 15, 2026 at 4:02 pm

    First, remember that inkscape: isnt’ a namespace, it’s just a convenient way of referring to a namespace that is defined in your XML root element. The namespace is http://www.inkscape.org/namespaces/inkscape, and depending on your XML, inkscape:groupmode might be identical to foo:groupmode. And of course, your <g> element is part of the SVG namespace, http://www.w3.org/2000/svg. To generate appropriate output with LXML, you would start with something like this:

    from lxml import etree
    root = etree.Element('{http://www.w3.org/2000/svg}svg')
    g = etree.SubElement(root, '{http://www.w3.org/2000/svg}g', id='layer-id')
    

    Which would get you:

    <ns0:svg xmlns:ns0="http://www.w3.org/2000/svg">
      <ns0:g id="layer-id"/>
    </ns0:svg>
    

    To add in the inkscape-specific attributes, you would do this:

    g.set('{http://www.inkscape.org/namespaces/inkscape}groupmode', 'layer')
    g.set('{http://www.inkscape.org/namespaces/inkscape}label', 'layer-label')
    

    Which would get you:

    <ns0:svg xmlns:ns0="http://www.w3.org/2000/svg">
      <ns0:g xmlns:ns1="http://www.inkscape.org/namespaces/inkscape" id="layer-id" ns1:groupmode="layer" ns1:label="layer-label"/>
    </ns0:svg>
    

    Which believe it or not is exactly what you want. You can clean up the namespace labels a bit by passing an nsmap= parameter when creating your root element. Like this:

    NSMAP = {
      None: 'http://www.w3.org/2000/svg',
    'inkscape': 'http://www.inkscape.org/namespaces/inkscape',
    }
    
    root = etree.Element('{http://www.w3.org/2000/svg}svg', nsmap=NSMAP)
    

    With this in place, the final output would look like this:

    <svg xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns="http://www.w3.org/2000/svg">
      <g id="layer-id" inkscape:label="layer-label" inkscape:groupmode="layer"/>
    </svg>
    

    More information in the LXML documentation.

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

Sidebar

Related Questions

When generating IL using DynamicMethod it's possible to call methods and access fields that
In my web application, I am generating a SVG file which contains a header
I'm seeing a strange rendering issue in an SVG that I'm generating. I've narrowed
I am generating a pdf file in asp.net c# using itextsharp. i am not
I am generating xml file dynamically and getting error when i include newstext .
Are there documented pylons or turbogears2 widgets for generating SVG markup as components and
Generating normal columnar data in excel file is quite easy but does any one
Im generating a file to present to the user for download, but the server
I'm generating json from a Rails app, and am filtering fields using the format.json
I have a large SVG file (approx. 60 MB, 10000x10000 pixels but with the

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.