Checking and deleting attributes in SVG using Batik in Java

家住魔仙堡 提交于 2019-12-11 10:46:03

问题


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.

Can I delete it?


回答1:


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
        }

to delete call

        svg.removeAttribute("viewBox")


来源:https://stackoverflow.com/questions/13229690/checking-and-deleting-attributes-in-svg-using-batik-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!