SVG Batik Root element namespace does not match th

2019-06-17 08:27发布

Few weeks ago, it was working PERFECTLY my SVG, but somehow it stopped working and I don't know the cause because the error fired on the server wasn't helpful. It happens when I transfer the svg file to my pdf:

Root element namespace does not match that requested:
Requested: http://www.w3.org/2000/svg
Found: null. Stacktrace follows:
org.apache.batik.bridge.BridgeException: Root element namespace does not match that requested:
Requested: http://www.w3.org/2000/svg
Found: null
    at org.apache.batik.bridge.BridgeContext.getReferencedNode(BridgeContext.java:780)
    at org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:796)
    at org.apache.batik.bridge.CSSUtilities.convertClipPath(CSSUtilities.java:719)
    at org.apache.batik.bridge.AbstractGraphicsNodeBridge.buildGraphicsNode(AbstractGraphicsNodeBridge.java:146)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:224)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
    at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:219)
    at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
    at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:82)
    at net.sf.jasperreports.renderers.BatikRenderer.ensureSvg(BatikRenderer.java:192)
    at net.sf.jasperreports.renderers.BatikRenderer.getDimension(BatikRenderer.java:141)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportImage(JRPdfExporter.java:1351)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportElements(JRPdfExporter.java:774)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportPage(JRPdfExporter.java:738)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReportToStream(JRPdfExporter.java:616)
    at net.sf.jasperreports.engine.export.JRPdfExporter.exportReport(JRPdfExporter.java:364)
    at com.scacp.operation.MonitoringWellController$_closure13.doCall(MonitoringWellController.groovy:749)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

I don't what it means, my xml svg(on xml validator website) is valid code. I'm writing like this:

file.write('<?xml version="1.0" encoding="UTF-8"?> \n'
+ '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> \n'
+ '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="705px" height="1000px" viewBox="0 0 705 1000" enable-background="new 0 0 705 1000" xml:space="preserve"> \n'
+ svgimage + '\n'
+ '</svg>');

The variable svgimage is a bunch of g, defs, text, images, etc (really big, like 1k of lines)

2条回答
乱世女痞
2楼-- · 2019-06-17 08:56

I'm suggesting this but not fully understanding the problem - did the transfer to pdf work at some point and then fail suddenly.

In the document type declaration: w3.org mentions using a 'flat' DTD in the System Identifier, which is a single flattened DTD, instead of multiple files.

w3.org - SVG NampeSpace, Public Identifier and System Identifier :

"Note that DTD listed in the System Identifier is a modularized DTD (i.e. its contents are spread over multiple files), which means that a validator may have to fetch the multiple modules in order to validate. For that reason, there is a single flattened DTD available that corresponds to the SVG 1.1 modularized DTD. It can be found at http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-flat.dtd."

查看更多
做自己的国王
3楼-- · 2019-06-17 09:10

I had a lot of work to find the cause over +1k of lines on my xml and It's a tag that svg created and w3 didn't recognized, which is clipPath and clip-path and by removing them, works perfectly:

<clipPath id="_ABSTRACT_RENDERER_ID_0"> //removed
...
</clipPath>

<g clip-path="url(http://mypage.com/344#_ABSTRACT_RENDERER_ID_0)"> //remove the attribute clip-path
...
</g>

Somehow, the w3 didnt recognized the url(...) by simply removing this, it works. And It's strange, it was always there.

查看更多
登录 后发表回答