batik - 如何使用蜡染将 svg 解析为 Document?
问题描述
我的 svg 喜欢这个:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
...
</svg>
不止一个xmlns
,怎么定义xmlns
呢batik
?以及如何解析为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)
``
解决方案
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(uri);
推荐阅读
- spring - repo.sping.io url 大部分时间都处于关闭状态,因此无法使用 Spring Cloud 数据流服务器部署应用程序
- html - 如何在表格中的 TD 列之间添加间距?
- javascript - 下拉菜单需要多次点击才能打开
- python - 最小和最大功能来计算最小信用卡余额
- android - “命令失败:./gradlew installDebug”问题(react-native run-android)
- javascript - React Pagination:如何在点击时加载第二页数据
- html - 如果可能,我如何使用 selenium 来识别嵌套框架中的元素?
- wix3.10 - WiX 工具集灾难性故障运行 light.exe
- ios - 从另一个类访问@IBOutlet
- mysql - MySQL table.column 不更新