0
我有一張名片,ID和其他字段的學生卡SVG,我想通過Java編輯,因爲用戶使用GUI輸入它們。無法在Java中使用Batik編輯SVG?
我已經使用Batik成功解析了SVG,但是當我打開SVG文件時無法看到所做的更改。
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();
}
當我打印出一個用
System.out.println(svg.getTextContent());
它改變了,但是當我在記事本中打開SVG這是相同的SVG元素的值。
SVG
<text x="759" y="361" id="name" class="fil3 fnt3">STUDENT</text>
更新爲他人:與
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();
FileOutputWriter? –
對不起,FileWriter。 (自從我完成任何Java以來,這已經有一段時間了。) – heycam
您的更新#2看起來對我來說很合適。如果您仍然遇到麻煩,請在蠟染用戶郵件列表上詢問。 – heycam