Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking and deleting attributes in SVG using Batik in Java

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?

like image 476
Invader Zim Avatar asked Nov 20 '25 07:11

Invader Zim


1 Answers

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")
like image 113
Robert Longson Avatar answered Nov 22 '25 19:11

Robert Longson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!