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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:42:10+00:00 2026-05-26T17:42:10+00:00

My problem is specifically about some trouble I’m having parsing an Inkscape (XML) file,

  • 0

My problem is specifically about some trouble I’m having parsing an Inkscape (XML) file, but it’s solution should be applicable to any XML doc, so I feel it’s Stackoverflow relevant.

I’m trying to use the Nokogiri CSS selectors to get all the <g> elements that have the attribute inkscape:groupmode="layer". But the colon is causing the error:

Nokogiri::CSS::SyntaxError: unexpected ':' after 'inkscape'

My XML document looks like:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="744.09448819" height="1052.3622047" id="svg3720" version="1.1" inkscape:version="0.48.1 r9760" sodipodi:docname="test.svg">
  <defs id="defs3722">
    <inkscape:perspective sodipodi:type="inkscape:persp3d" inkscape:vp_x="0 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" id="perspective3728"/>
  </defs>
  <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="0.35" inkscape:cx="375" inkscape:cy="634.28571" inkscape:document-units="px" inkscape:current-layer="g2818" showgrid="false" inkscape:window-width="550" inkscape:window-height="483" inkscape:window-x="66" inkscape:window-y="471" inkscape:window-maximized="0"/>
  <metadata id="metadata3725">
    <rdf:RDF>
      <cc:Work rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
        <dc:title/>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1">
    <rect style="fill:#d2e149;fill-opacity:1;stroke:none" id="rect2812" width="211.42857" height="128.57143" x="168.57143" y="215.21933" ry="64.285713"/>
  </g>
  <g inkscape:label="Layer 1 copy copy" inkscape:groupmode="layer" id="g2818">
    <rect style="fill:#d2e149;fill-opacity:1;stroke:none" id="rect2820" width="211.42857" height="128.57143" x="145.71428" y="615.2193" ry="64.285713"/>
  </g>
</svg>

My selector looks like:

nokogiri_document.css('[inkscape:groupmode="layer"]').to_html

I also tried replacing the colon with a pipe

How do I write the CSS selector to work on the inkscape:groupmode attribute…or for that matter any foo:bar attribute?

  • 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-26T17:42:11+00:00Added an answer on May 26, 2026 at 5:42 pm

    Use XPath, specifying the namespace for the g elements. Since your root element declares the xmlns:svg to be the same as the new default namespace (xmlns) you can use svg as your prefix:

    require 'nokogiri'
    doc = Nokogiri.XML(IO.read('contents.xml'))
    layers = doc.xpath('//svg:g[@inkscape:groupmode="layer"]')
    
    p layers.map{ |layer| layer['id'] }
    #=> ["layer1", "g2818"]
    

    Decoded, the above XPath says:

    • // – At any level of the document
    • svg:g – …find g elements with a namespace matching the svg namespace
    • […] – …but only if the contents of this are met
    • @inkscape:groupmode – …there is an attribute (@) named groupmode with a namespace matching inkscape
    • ="layer" – and the intrinsic value of this attribute is the text layer.

    Alternatively, if you’re just trying to read this file (and not manipulate and re-save it) you can use the gross-but-simplifying hack of removing all namespaces. In this case, your original code works simply:

    doc.remove_namespaces!
    p doc.css('g[groupmode="layer"]').map{ |g| g['id'] }
    #=> ["layer1", "g2818"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a slight problem with my SDL/Opengl code, specifically, when i try to
I'm dealing specifically with C++, but this is really language-agnostic. Just to give some
This problem is specifically about Sun Java JVM running on Linux x86-64 . I'm
When I first started learning about Spring, things were configured in the applicationContext.xml file.
I'm experiencing the same problem in this previous stackoverflow.com post . Specifically, I seem
I'm running in to the same problem this individual has . Specifically, I'm trying
i'm having problem to deal with charset in ruby on rails app, specificially in
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
Problem: I have two spreadsheets that each serve different purposes but contain one particular
I was wondering how to go about form validation in rails. Specifically, here is

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.