Using Apache Batik& need to get the ID of an element? Try doing this:
// Get ID of first g element
NodeList gElements = symbolSVGRoot.getElementsByTagNameNS(svgNS, “g”);
Element firstGElement = (Element)gElements.item(0);
String gID = firstGElement.getAttribute(“id”);
Need to get the width value of the svg element? Try doing this:
String widthAttribute = symbolSVGRoot.getAttribute(“width”);
If the value has units specified, such as mm, do this to get the actual value:
String patternWidth = widthAttribute.substring(0, widthAttribute.length()-2);
Now to figure out my next problem:
How to use Batik to get the total length of a path. Apparently you can use SVGPathElement.getTotalLength, but it’s just not working for me yet.
Leave a Reply
You must be logged in to post a comment.