On Sep 21, 9:53 am, wtw <
wtwel...@rcgmbh.com> wrote:
> ....
> The complete contents of the SVG-textfile look like this (originally
> copied from what Raphael produces):
>
> <svg xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;"
> ...
>
> Could you give me a hint what I need to change in order to get it
> work?
Doing something a bit like that:
var svgText = [
'<svg',
' xmlns="
http://www.w3.org/2000/svg"',
' xmlns:xlink="
http://www.w3.org/1999/xlink"',
' version="1.1"',
' x="0px" y="0px"',
' width="472px" height="580px"',
' viewBox="0 0 472 580"',
' enable-background="new 0 0 472 580"',
' xml:space="preserve">',
' <g id="viewport"',
' transform="matrix(0.563731, 0, 0, 0.563731, -6.78611,
-41.1079)">',
' <path',
' fill="#ffffff"',
' stroke="#888a8b"',
' d="M269,234.3L268.3,234.6"',
' style="stroke-miterlimit: 10; stroke-width: 1; stroke-
opacity: 0.5;"',
' stroke-miterlimit="10"',
' stroke-width="1"/>',
' </g>',
'</svg>'
].join('\n');
$(function() {
$('#canvas').html(svgText);
});
results in a DOM element for the root svg element in the xhtml
namespace which is not what one might hope for. As you say, the name
"html" on the jQuery method is a clue. Regrettably, there doesn't seem
to be a jQuery "xhtml" method.
> First thing I will try is move away from the jQuery method and
> look at methods like "createElementNS" to insert the SVG elements "by
> hand". By what you said, this might fix my problem.
Yes, that's probably the best approach if you're building the SVG DOM
tree from some other source.
If you already have the SVG as XML text there are other techniques for
turning it into a suitable DOM tree. See, for example, the first parts
of the "JavaScript and XML" chapter of David Flanagan's "JavaScript:
The Definitive Guide".