我的svg喜欢这样:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
...
</svg>不仅仅是一个xmlns,如何在batik中定义xmlns?以及如何解析为Document
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
File file = new File(svgURI);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
Document doc = f.createDocument(svgNS, "svg", file.toURI().toString());上面的代码在运行时有异常:
Exception in thread "main" org.w3c.dom.DOMException: The current document is unable to create an element of the requested type (namespace: http://www.w3.org/2000/svg, name: usrs).
at org.apache.batik.dom.AbstractNode.createDOMException(AbstractNode.java:407)
at org.apache.batik.anim.dom.SVGDOMImplementation.createElementNS(SVGDOMImplementation.java:202)
at org.apache.batik.anim.dom.SVGOMDocument.createElementNS(SVGOMDocument.java:373)
``发布于 2021-04-14 11:35:35
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(uri);https://stackoverflow.com/questions/61317546
复制相似问题