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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:34:19+00:00 2026-06-16T22:34:19+00:00

I am trying to have a SVG which pulls some text from a .txt

  • 0

I am trying to have a SVG which pulls some text from a .txt file and displays it.
Here is my code so far.

<svg width="10cm" height="3cm" viewBox="0 0 1000 300" version="1.1"
     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">

  <text x="100" y="200" font-size="45" fill="red" >
    <tref xlink:href="sensors.txt"/>
  </text>

</svg>

I don’t understand why its not working.

  • 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-16T22:34:21+00:00Added an answer on June 16, 2026 at 10:34 pm

    To fix your non-functional <tref> elements, you can add a script to the end of the SVG that loads the desired text files via Ajax:

    <svg width="10cm" height="3cm" viewBox="0 0 1000 300" version="1.1"
         xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <text x="100" y="200" font-size="45" fill="red" >
        <tref xlink:href="sensors.txt"/>
      </text>
      <script type="text/javascript">
        var trefs = document.getElementsByTagName("tref");
        for (var i=0; trefs[i]; i++) {
          var xhr = new XMLHttpRequest();
          xhr.open("GET",trefs[i].getAttributeNS("http://www.w3.org/1999/xlink","href"),false);
          xhr.send("");
          trefs[i].parentNode.replaceChild(document.createTextNode(xhr.responseText),trefs[i]);
        }
      </script>
    </svg>
    

    Of course, this only works for referencing text files, as you do. This could be stylistically refined and, if needed, also be made working for references of text via IDs, like xlink:href="#textId', even for referenced IDs from external files, like xlink:href="other.svg#textId".

    I’m not sure whether it can sensibly be sniffed whether the browser already supports all needed aspects of <tref> to only run the script if necessary.

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

Sidebar

Related Questions

I have never code in Python and trying to switch from Javascrpt/SVG. Being confused
Afternoon, I am trying have an HTML file containing a frameset which contains two
Trying to have my PHP script return some SQL table queries. Here's my script
I have an SVG file that I've added information to and I am trying
I have trying to learn MVC4 Web API. I am running my project from
I have a cache directory I'm trying to have ignored by git which lives
I'm trying to have a fixed width sidebar with a 100% height, next to
I have a website which uses SVG for an interactive client side thingamabob. I
I have a button which draws a line and some dots on that line
Let's say I have a resource file which exports mc1 with 4 frames in

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.