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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:36:32+00:00 2026-06-12T21:36:32+00:00

I have a web service method that parses an SVG string to remove certain

  • 0

I have a web service method that parses an SVG string to remove certain elements and then return it back.

Here is part of the SVG string:

<g id="wrapper">
    <g id="inner">
        <title>Layer 1</title>
...etc

This is the code:

XDocument x2 = XDocument.Parse(svgString);

var inner = (from el in x2.Root.Elements("g")
    where (string)el.Attribute("id") == "inner"
    select el);

inner.Remove();

return x2.ToString();

Firstly, why is the Count of inner 0?

Secondly, is this the correct way to “remove” the element or do I need to save the XDocument somehow before returning it?

edit: here is the full SVG string:

    <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"[]>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
    x="0px" y="0px" width="374.173px" height="524.409px" viewbox="0 0 374.173 524.409"
    enable-background="new 0 0 374.173 524.409" xml:space="preserve">

<g id="wrapper">
<g id="inner">
<title>Layer 1</title>
    <defs>
        <rect id="SVGID_1_" x="16.086" y="98.896" width="344.903" height="413.334" />
    </defs>
    <clipPath id="SVGID_2_">
        <use xlink:href="#SVGID_1_" overflow="visible" />
    </clipPath>
    <g clip-path="url(#SVGID_2_)">
        <defs>
            <rect id="SVGID_3_" x="-8.96" y="53.896" width="382.524" height="473.956" />
        </defs>
        <clipPath id="SVGID_4_">
            <use xlink:href="#SVGID_3_" overflow="visible" />
        </clipPath>
        <g transform="matrix(1 0 0 1 3.341429e-007 -1.529841e-006)" clip-path="url(#SVGID_4_)">

                <image overflow="visible" width="367" height="445" id="img11" xlink:href="data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEARQBFAAD/7AARRHVja3kAAQAEAAAAHgAA/+4AIUFkb2JlAGTAAAAAAQMA EAMCAwYAAAlpAAAVEAAANsH/2wCEABALCwsMCxAMDBAXDw0PFxsUEBAUGx8XFxcXFx8eFxoaGhoX Hh4jJSclIx4vLzMzLy9AQEBAQEBAQEBAQEBAQEABEQ8PERMRFRISF...........">
            </image>
        </g>
    </g>
</g>
</g>

<g>
     <title>Layer 2</title>
     <text transform="matrix(1 0 0 1 61.3745 48.5068)"><tspan x="0" y="0" fill="#9FA1A4" font-family="'Noteworthy-Bold'" font-size="24">testing 123</tspan></text>
     </g>

</svg>
  • 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-12T21:36:33+00:00Added an answer on June 12, 2026 at 9:36 pm

    Elements searches direct children, so if your structure is nested in some root tag, direct children of x2.Root will be <g id="wrapper">. Use Descendants instead:

    var inner = x2.Root.Descendants("g")
       .Where(e => e.Attribute("id").Value == "inner");
    

    Edit: since your root node defines default namespace, you need to include that in query:

    XNamespace n = @"http://www.w3.org/2000/svg";
    var inner = x2.Root
        .Descendants(n + "g")
        .Where(e => e.Attribute("id") != null)
        .Where(e => e.Attribute("id").Value == "inner")
    

    Here’s useful link dealing with LINQ2XML and namespaces issues.

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

Sidebar

Related Questions

I have a web service with a method that has two string parameters. When
i have web service in php which contain method (login) that should return false
I have a Web Service with Just one Web Method that returns a boolean
I have a simple web service that will have one method: DoTransactions(xlm) Now the
I have a web service that returns a raw string of JSON data (sample
I have a app that parses all my data from my web service as
I have a web service method where I would like to throw some custom
I have a web service method in which I create a particular type of
When I call, the service's method, I have Web Service Exception happening which I
I have a simple web service method which I'm trying to convert: <WebMethod()> _

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.