I have a student card SVG that has name, id and other field that I want to edit through Java, as the user inputs them using GUI.
I have successfully parsed the SVG using Batik but I can't see the changes that I made in 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 out one the of SVG element's value using
System.out.println(svg.getTextContent());
It's changed but when I open the SVG in notepad it's the same.
SVG
<text x="759" y="361" id="name" class="fil3 fnt3">STUDENT</text>
UPDATE FOR OTHERS: Solved with
File file = new File("new.svg");
FileWriter fWriter = new FileWriter(file);
XmlWriter.writeXml(svg, fWriter, false);
// Most crucial part, It wasn't working just because of flush
fWriter.close();