Java:Batik例外

时间:2014-06-02 13:48:35

标签: java svg batik

提前感谢您的帮助! 我在使用带有svg文件的蜡染时遇到了一个问题,我实际上是用我从html元素获得的svg创建的。 我得到的例外是:

org.apache.batik.bridge.BridgeException:根元素之前的文档中的标记必须格式正确。     在org.apache.batik.bridge.BridgeContext.getReferencedNode(BridgeContext.java:780)     在org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:796)     在org.apache.batik.bridge.CSSUtilities.convertClipPath(CSSUtilities.java:719)     在org.apache.batik.bridge.AbstractGraphicsNodeBridge.buildGraphicsNode(AbstractGraphicsNodeBridge.java:146)     在org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:224)     在org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)     在org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:219)     在org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)     在org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:82)     at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:208)     at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTranscoder.java:92)     at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstractTranscoder.java:142)     at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstractTranscoder.java:156)     在com.test.chart.server.GreetingServiceImpl.svgtopng(GreetingServiceImpl.java:110)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)     在com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)     在com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)     在com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)     在org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)     在org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)     在org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)     在org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)     在org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)     在org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)     在org.mortbay.jetty.Server.handle(Server.java:324)     在org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)     at org.mortbay.jetty.HttpConnection $ RequestHandler.content(HttpConnection.java:843)     在org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)     在org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)     在org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)     在org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)     在org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:488)

我已经检查了所有内容,从一个正常工作的svg标头,更改内容,查看我的svg输入,以确保一切看起来不错但仍然获得相同的错误。 svg看起来像这样(对不起......):

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" style="overflow: hidden;" height="2500" width="1304"><defs id="defs"><clipPath id="_ABSTRACT_RENDERER_ID_0"><rect height="1644" width="806" y="428" x="249"></rect></clipPath></defs><rect fill="#ffffff" stroke-width="0" stroke="none" height="2500" width="1304" y="0" x="0"></rect><g><rect fill="#ffffff" fill-opacity="0" stroke-width="0" stroke="none" height="6" width="237" y="428" x="1061"></rect><g><rect fill="#ffffff" fill-opacity="0" stroke-width="0" stroke="none" height="6" width="237" y="428" x="1061"></rect><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="433.1" x="1069" text-anchor="start">Value</text></g><rect fill="#3366cc" stroke-width="0" stroke="none" height="6" width="6" y="428" x="1061"></rect></g></g><g><rect fill="#ffffff" fill-opacity="0" stroke-width="0" stroke="none" height="1644" width="806" y="428" x="249"></rect><g clip-path="url(http://127.0.0.1:8888/ChartTest.html?gwt.codesvr=127.0.0.1:9997#_ABSTRACT_RENDERER_ID_0)"><g><rect fill="#cccccc" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="249"></rect><rect fill="#cccccc" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="450"></rect><rect fill="#cccccc" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="652"></rect><rect fill="#cccccc" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="853"></rect><rect fill="#cccccc" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="1054"></rect></g><g><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="0" y="460" x="249"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="80" y="624" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="160" y="788" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="241" y="953" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="321" y="1117" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="402" y="1281" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="482" y="1445" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="563" y="1610" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="643" y="1774" x="250"></rect><rect fill="#3366cc" stroke-width="0" stroke="none" height="101" width="724" y="1938" x="250"></rect></g><g><rect fill="#333333" stroke-width="0" stroke="none" height="1644" width="1" y="428" x="249"></rect></g></g><g></g><g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="20" font-family="Arial" y="2101" x="249.5" text-anchor="middle">0,0</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="20" font-family="Arial" y="2101" x="450.75" text-anchor="middle">2,5</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="20" font-family="Arial" y="2101" x="652" text-anchor="middle">5,0</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="20" font-family="Arial" y="2101" x="853.25" text-anchor="middle">7,5</text></g><g><text fill="#444444" stroke-width="0" stroke="none" font-size="20" font-family="Arial" y="2101" x="1054.5" text-anchor="middle">10,0</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="512.75" x="243" text-anchor="end">point0</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="677.0500000000001" x="243" text-anchor="end">point1</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="841.35" x="243" text-anchor="end">point2</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1005.6500000000001" x="243" text-anchor="end">point3</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1169.9499999999998" x="243" text-anchor="end">point4</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1334.25" x="243" text-anchor="end">point5</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1498.55" x="243" text-anchor="end">point6</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1662.85" x="243" text-anchor="end">point7</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1827.15" x="243" text-anchor="end">point8</text></g><g><text fill="#222222" stroke-width="0" stroke="none" font-size="6" font-family="Helvetica" y="1991.45" x="243" text-anchor="end">point9</text></g></g></g><g><g><text fill="#222222" stroke-width="0" stroke="none" transform="rotate(-90 121 1250)" font-style="italic" font-size="20" font-family="Arial" y="1250" x="121" text-anchor="middle">Name</text></g></g><g></g></svg>

如果您需要更多信息,请问我! 非常感谢你的帮助, Coralie

1 个答案:

答案 0 :(得分:1)

问题不在于XML序言。即使你完全删除它也会失败。

我做了一点实验,罪魁祸首就是这样:

<g clip-path="url(http://127.0.0.1:8888/ChartTest.html?gwt.codesvr=127.0.0.1:9997#_ABSTRACT_RENDERER_ID_0)">

尝试在另一个网址引用剪辑路径。 Batik不喜欢它。

如果您将其更改为简单:

<g>

该文件似乎渲染得很好。