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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:53:21+00:00 2026-05-31T22:53:21+00:00

I have a page successfully asking for and parsing some raw SVG from a

  • 0

I have a page successfully asking for and parsing some raw SVG from a JSON object. The problem is taking that SVG and putting it into a page. I have:

function addSVGToPage(SVGToAdd) {
    var entry, decodedEntry;
    makeAJAXCall(SVGToAdd, function (returnedJSON) {
        var svgElement;
        entry = decodeURIComponent(escape(atob(returnedJSON.data.content.replace(/\s/g, ''))));
        decodedEntry = entry.split('\n').slice(2).join('\n');  //remove the first two elements in the file that prevent them from being added as an actual file.

        $(insertArea).append(decodedEntry);  //insertArea is a <div>
    });
}

But it does not seem to putting anything on the page.

What is the best way to go about putting the returned SVG (as a string) on to the page?

Edit: Solution!

The solution is that (due to security or namespce, IDK) you need to parse the raw string as a XML then import it into the DOM. As below

function addSVGToPage(SVGToAdd) {
    var entry, decodedEntry, xmlDoc, importedNode;
    makeAJAXCall(SVGToAdd, function (returnedJSON) {
        var svgElement;
        entry = decodeURIComponent(escape(atob(returnedJSON.data.content.replace(/\s/g, ''))));
        decodedEntry = entry.split('\n').slice(2).join('\n');  //remove the first two elements in the file that prevent them from being added as an actual file.
        xmlDoc = $.parseXML(decodedEntry); // turn the string into an xml fragment

        importedNode = document.importNode(xmlDoc.documentElement, true);
        document.body.appendChild(importedNode);
    });
}

Did not end up using the d3 method, although it was a good one, because the data coming back was JSON containing a base64 encoded string of the SVG (plus some extra declaration stuff) and jQuery capable of handling that without adding in an extra library.

Edit 2:
For those interested: http://dougmiller.github.com/SVG-Shapes is the link to where it is set up.

  • 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-31T22:53:23+00:00Added an answer on May 31, 2026 at 10:53 pm

    d3 has nice means of doing this:

    d3.xml("tuto3.svg", "image/svg+xml", function(xml) {
       var importedNode = document.importNode(xml.documentElement, true);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that when submitted successfully generates new elements on the page
I have a page that makes use of the jTweetsAnywhere code (from here )
I am facing a critical problem. I have a page that has two parts.
I have successfully bound a control to a property on my page. The property
on my page, I have a listbox in an update panel. I am successfully
i have a php page that redirects (if successful) to another php page like
I have a page in which i can successfully use the jquery focus function
I have a page that collects information on two objects of the same type.
I have an ASP.NET MVC web page that has a file upload control. Under
I have a page called category.php5 that uses $_GET[category] to fetch the right content

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.