javascript - Push SVG String into Dom? -


I have a JavaScript variable that looks like this:

  my_svg_image = '& Lt; Circle cx = "227.58331298828125" cy = "102" r = "3" style = "fill: black; stroke-width: 0" /> ';  

This was loaded from my database. Is there any way that I can parse that string and add it to Java in Java? I have svgweb set up, but I can not see how I can get it to parse this string. What other libraries can help?

Have you tried javascript property?

EDIT: You can only use internal HTML properties for Html elements, so that you can use a string in which to add the entire STVG image to an HTML element. But you can not add an SVG element to the existing SVG element.

Example:

  & lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt ;! DOCTYPE HTML Public "- // W3C // DTD XHTML 1.1 Plus Methal 2.0 Plus SVG 1.1 / n" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd "& Gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" xmlns: svg = "http://www.w3.org/2000/svg" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "application / xHTML + xml; charset = UTF-8" /> & Lt; Script type = "text / javascript" & gt; & Lt ;! [CDATA [Function Test () {var Newsweig = document.getElementById ("svg-wrapper"); Var svgstr = '& lt; Svg: svg height = "300" width = "700" id = "svg-container" & gt; & Lt; Svg: circle cx = "150px" cy = "100px" r = "30px" /> & Lt; / Svg: svg & gt; '; Newsvg.innerHTML = svgstr; }] & Gt; & Lt; / Script & gt; & Lt; Title & gt; SVG Dome & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div id = "svg-wrapper" & gt; & Lt; / Div & gt; & Lt; Input type = "button" onclick = "javascript: test ();" Value = "SVG generates" /> gt; & Lt; Br / & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

If you want to add a circle to the existing inline SVG, then you have to add it using DOM methods (and possibly before parse your string to remove the required attribute values ​​first. Will happen).

>

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -