使用Java中的Batik检查和删除SVG中的属性 [英] Checking and deleting attributes in SVG using Batik in Java
本文介绍了使用Java中的Batik检查和删除SVG中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题基本上说明了一切.如何检查SVG是否具有viewBox属性?我正在使用蜡染库.我需要这个,因为我需要(至少)通知用户有一个viewBox属性.
The question basically says it all. How can I check if SVG has a viewBox attribute? I am using Batik lib. I need this because I need to (at least) notify the user that there is a viewBox attribute.
我可以删除它吗?
推荐答案
使用org.w3c.dom类,您可以按照以下方式进行操作...
Using org.w3c.dom classes you'd do something along these lines...
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
URL url = new URL(getCodeBase(), "fileName.svg");
Document doc = f.createDocument(url.toString());
Element svg = doc.getDocumentElement();
if (svg.hasAttribute("viewBox")) {
// notify the user somehow
}
删除通话
svg.removeAttribute("viewBox")
这篇关于使用Java中的Batik检查和删除SVG中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文