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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:58:21+00:00 2026-06-17T14:58:21+00:00

I am trying to find an XML element within an SVG (font) file based

  • 0

I am trying to find an XML element within an SVG (font) file based on the content of an attribute, like so:

font = et.ElementTree(file='fontfile.svg')
glyph = font.find('//n:glyph[@unicode="%s"]' % symbol, namespaces={'n': SVGNS})

Glyph examples — what I’m trying to match to — are:

<glyph unicode="&#xa9;" horiz-adv-x="1792" d="M834 ... -40t-121 -18z " />
<glyph unicode="C" horiz-adv-x="1509" d="M1766 338q-49 ... 83.5v-215z" />

Problem is that when, for example,

symbol = "C"

it works fine (there is a match), but when

symbol = "&#xa9;"

it doesn’t. I suspect that there is a unicode interpretation in one direction of the matching, but not the other. What is the correct way to resolve this?

  • 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-17T14:58:22+00:00Added an answer on June 17, 2026 at 2:58 pm

    Building on unutbu’s answer, when you do ET.fromstring, it translates the HTML entities into unicode objects as attributes.

    >>> import lxml.etree as ET
    >>> 
    >>> content = '''\
    ... <root xmlns="SVGNS">
    ... <glyph unicode="&#xa9;" horiz-adv-x="1792" d="M834 ... -40t-121 -18z " />
    ... <glyph unicode="C" horiz-adv-x="1509" d="M1766 338q-49 ... 83.5v-215z" />
    ... </root>'''
    >>> font = ET.fromstring(content)
    >>> font
    <Element {SVGNS}root at 0x7fd7ab978410>
    >>> font.xpath('//n:glyph', namespaces={'n':'SVGNS'})[0].attrib
    {'horiz-adv-x': '1792', 'unicode': u'\xa9', 'd': 'M834 ... -40t-121 -18z '}
    

    So, the answer at the end of the day is that the HTML entity &#xa9; no longer exists as such in font, to search for it it needs to be converted into unicode. Some ways to do that are explained here.

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

Sidebar

Related Questions

I am trying to find the last element in my xml, which looks like:
My xml element content is having special characters like <,>,[,]. I want to find
I'm trying to find if a certain element is present in a XML file
I'm trying to find the inner text value of an element using LINQ-to-XML (an
I'm trying to find an implementation of java.io.FileFilter which understands patterns like these: **/*.xml
I'm trying to find an element from a kml file using element trees as
I'm trying to retrieve values from an XML file and I find some values
I am trying to read a element form a xml file to add new
I am trying to parse XML with jsoup, but I can't find any examples
Im trying to identify an attribute using SAX. My XML is as follows <DAY

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.