I have a student SVG that has a name, id, and another field that I want to edit through Java, as the user enters them using the GUI.
I successfully parsed SVG using Batik, but I donβt see the changes I made in the SVG file when I open it.
String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); String uri = "card.svg"; try { Document doc = f.createDocument(uri); NodeList nodeList = doc.getChildNodes(); Element svg = doc.getElementById("name"); svg.setTextContent("Your Name"); System.out.println(svg.getTextContent()); } catch (IOException e) { e.printStackTrace(); }
When I print a single SVG element value using
System.out.println(svg.getTextContent());
It has changed, but when I open SVG in notepad, it is the same.
Svg
<text x="759" y="361" id="name" class="fil3 fnt3">STUDENT</text>
UPDATE FOR OTHERS: Baxin
File file = new File("new.svg"); FileWriter fWriter = new FileWriter(file); XmlWriter.writeXml(svg, fWriter, false);
java xml svg batik
Mirwise Khan Jan 23 '17 at 6:17 2017-01-23 06:17
source share