Note that there are some explanatory texts on larger screens.

plurals
  1. POGet lowercase tag names with xmldom.XMLSerializer in Node.js
    text
    copied!<p>I'm using Node.js to save a D3 graph to a file. The code is returning the SVG tags as all-caps instead of lowercase tags:</p> <pre class="lang-xml prettyprint-override"><code>&lt;SVG height="300" width="460" xmlns="http://www.w3.org/2000/svg"&gt; &lt;G transform="translate(230,150)"&gt; &lt;PATH d="M6.123031769111886e-15,-100A100,100 0 0,1 90.12430862004372,43.33138580473872L45.06215431002186,21.66569290236936A50,50 0 0,0 3.061515884555943e-15,-50Z" fill="#1f77b4"/&gt; &lt;PATH d="M90.12430862004372,43.33138580473872A100,100 0 0,1 4.27399232527422,99.90862319941907L2.13699616263711,49.954311599709534A50,50 0 0,0 45.06215431002186,21.66569290236936Z" fill="#aec7e8"/&gt; &lt;PATH d="M4.27399232527422,99.90862319941907A100,100 0 0,1 -64.73671010012329,76.21783495621347L-32.368355050061645,38.10891747810673A50,50 0 0,0 2.13699616263711,49.954311599709534Z" fill="#ff7f0e"/&gt; &lt;PATH d="M-64.73671010012329,76.21783495621347A100,100 0 0,1 -99.89978970073908,-4.4757142165364L-49.94989485036954,-2.2378571082682A50,50 0 0,0 -32.368355050061645,38.10891747810673Z" fill="#ffbb78"/&gt; &lt;PATH d="M-99.89978970073908,-4.4757142165364A100,100 0 0,1 -1.836909530733566e-14,-100L-9.18454765366783e-15,-50A50,50 0 0,0 -49.94989485036954,-2.2378571082682Z" fill="#2ca02c"/&gt; &lt;/G&gt; &lt;/SVG&gt; </code></pre> <p>The node.js script:</p> <pre class="lang-js prettyprint-override"><code>require('d3'); var xmldom = require('xmldom'); var dataset = { apples: [53245, 28479, 19697, 24037, 40245], }; var width = 460, height = 300, radius = Math.min(width, height) / 2; var color = d3.scale.category20(); var pie = d3.layout.pie() .sort(null); var arc = d3.svg.arc() .innerRadius(radius - 100) .outerRadius(radius - 50); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .append("g") .attr("transform", "translate(" + width / 2 + "," + height / 2 + ")"); var path = svg.selectAll("path") .data(pie(dataset.apples)) .enter().append("path") .attr("fill", function (d, i) { return color(i); }) .attr("d", arc); var svgObject = d3.select("svg").attr('xmlns', 'http://www.w3.org/2000/svg'); var xml = new xmldom.XMLSerializer().serializeToString(svgObject[0][0]); console.log(xml); </code></pre> <p>How do you get the tag names as lowercase names (which SVG needs)?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload