question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nodejs xmldom svg support

See original GitHub issue

I’d like to create an svg Element in nodejs using xmldom and then generate an svg barcode just like you can when using jsBarcode in a browser context.

const { DOMImplementation } = require('xmldom');
const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);

const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

jsBarcode(svgNode, 'test', {
  format: 'CODE128C',
  displayValue: false,
  width: 4,
  height: 100
});

I’d hope it should be able to re-use the same renderers.SVGRenderer from here, would need to figure out how to tell if it’s passed an xmldom svg element

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
lindellcommented, May 11, 2017

Works like this:

    const { DOMImplementation, XMLSerializer } = require('xmldom');
    const xmlSerializer = new XMLSerializer();
    const document = new DOMImplementation().createDocument('http://www.w3.org/1999/xhtml', 'html', null);
    const svgNode = document.createElementNS('http://www.w3.org/2000/svg', 'svg');

    JsBarcode(svgNode, 'test', {
      xmlDocument: document
    });

    let xml = xmlSerializer.serializeToString(svgNode);
1reaction
lindellcommented, May 17, 2017

Just released JsBarcode v3.7.0 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

svgdom - npm
Straightforward DOM implementation for SVG, HTML and XML. ... Start using svgdom in your project by running `npm i svgdom`.
Read more >
xmldom set SVG fill attributes on child elements - Stack Overflow
I tried to set attribute to child element, and got child.setAttribute() is not a function error. Thanks for helping. node.js · svg ·...
Read more >
Reading and writing XML in Node.js - LogRocket Blog
When you think about Node.js, XML probably isn't the first thing that ... SVG is an XML-based image format supported by all major...
Read more >
Convert SVG to PNG in Node.js using Sharp, no headless ...
Nowadays, SVG is nearly universal because it is widely supported in modern web browsers, ... Using xmldom to manipulate SVG in Node.js.
Read more >
Serving Clickable Scalable Vector Graphics (SVG) Part 1
Fortunately, since node.js has a fairly large community, it is not hard to find supporting tools that make the task pretty easy. Install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found