Get the xml content of SVG file using Javascript

Discuss SVG code, accessible via the XML Editor.
luckymax
Posts: 3
Joined: Sat Jun 23, 2012 12:41 am

Get the xml content of SVG file using Javascript

Postby luckymax » Sat Jun 23, 2012 12:53 am

Hi,

I have the following HTML code:
<.html"font-size: 150%; line-height: 116%;">as string using javascript?

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Get the xml content of SVG file using Javascript

Postby brynn » Sat Jun 23, 2012 10:00 am

I assume it would be possible. But why can't you just open the XML Editor, and copy the content to a text file? Ooohh, I see! I surely don't understand why it's not possible to copy more than just one attribute, from the XML Editor.

Oh....well if you open an SVG file with a browser, so that you can see the XML code, you could probably copy it from there. I can't really explain how to do it, becuase I don't clearly understand it. But every now and then, when I click a link to see an SVG, I get a page full of XML instead of the image. I haven't figured out exactly how that happens. But it seems reasonable that should work. As for javascript, I'm clueless :P

Mathieu147
Posts: 55
Joined: Wed May 30, 2012 11:17 pm
Location: Belgium

Re: Get the xml content of SVG file using Javascript

Postby Mathieu147 » Tue Jun 26, 2012 1:06 am

Maybe if you send a XMLHttpRequest to retreive the file you could get its contents?

I use Inkscape 0.48 on Ubuntu 12.04.
English is not my natural language so excuse my mistakes.

luckymax
Posts: 3
Joined: Sat Jun 23, 2012 12:41 am

Re: Get the xml content of SVG file using Javascript

Postby luckymax » Tue Jun 26, 2012 4:31 pm

Mathieu147 wrote:Maybe if you send a XMLHttpRequest to retreive the file you could get its contents?

Thanks, I'll try it :)

Mathieu147
Posts: 55
Joined: Wed May 30, 2012 11:17 pm
Location: Belgium

Re: Get the xml content of SVG file using Javascript

Postby Mathieu147 » Tue Jun 26, 2012 7:32 pm

Maybe you are, but if you don't: use jQuery. That will be quite easy using the data() method.

I use Inkscape 0.48 on Ubuntu 12.04.
English is not my natural language so excuse my mistakes.

luckymax
Posts: 3
Joined: Sat Jun 23, 2012 12:41 am

Re: Get the xml content of SVG file using Javascript

Postby luckymax » Wed Jun 27, 2012 5:58 pm

Thank you, Mathieu147, I managed to do it!

Jelle
Posts: 78
Joined: Sat Nov 06, 2010 11:25 am

Re: Get the xml content of SVG file using Javascript

Postby Jelle » Wed Sep 05, 2012 3:54 pm

A simpler way than using an entire JQuery library is this one.. 10? lines of code..

http://127.0.0.1/httrack/svg_tutorials/ ... ntNode.svg

Don't forget to add this to the beginning of the script to make sure it works for all browsers.

if (typeof printNode=='undefined') {
printNode= function (el) {
return (new XMLSerializer()).serializeToString(el);
};


Return to “SVG / XML Code”