You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Julian Petri <de...@googlemail.com> on 2008/08/28 23:04:37 UTC
Scripting Java: Error << The attribute "xlink:href" of the element
Hello,
I want to add a <use> element to my svg document by creating and
adding it to the DOM with Java. Here's the code:
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
SVGDocument doc = svgCanvas.getSVGDocument();
Element qm = doc.createElementNS(svgNS, "use");
qm.setAttributeNS(null, "xlink:href", "#QuestionMark");
qm.setAttributeNS(null, "overflow", "visible");
qm.setAttributeNS(null, "width", "10.512");
qm.setAttributeNS(null, "height", "26.273");
qm.setAttributeNS(null, "x", "-5.256");
qm.setAttributeNS(null, "y", "-13.137");
qm.setAttributeNS(null, "transform", "matrix(1 0 0 -1 27.7561
292.2344)");
doc.getElementById("animatedBackground").insertBefore(qm, null);
System.out.println(DOMUtilities.getXML(qm));
At the line with the insertBefore() call I get the following error:
org.apache.batik.bridge.BridgeException:
file:/C:/Users/Julian/workspace/Multiquiz/src/gui/svg/mq-login.svg:0
The attribute "xlink:href" of the element <use> is required
at org.apache.batik.bridge.SVGUseElementBridge.buildCompositeGraphicsNode(SVGUseElementBridge.java:120)
at org.apache.batik.bridge.SVGUseElementBridge.createGraphicsNode(SVGUseElementBridge.java:98)
at org.apache.batik.bridge.GVTBuilder.build(GVTBuilder.java:138)
at org.apache.batik.bridge.SVGGElementBridge.handleElementAdded(SVGGElementBridge.java:123)
at org.apache.batik.bridge.SVGGElementBridge.handleDOMNodeInsertedEvent(SVGGElementBridge.java:107)
at org.apache.batik.bridge.BridgeContext$DOMNodeInsertedEventListener.handleEvent(BridgeContext.java:1601)
at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:324)
at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:366)
at org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:258)
at org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1014)
at org.apache.batik.dom.AbstractParentNode.fireDOMNodeInsertedEvent(AbstractParentNode.java:422)
at org.apache.batik.dom.AbstractParentNode.insertBefore(AbstractParentNode.java:106)
at gui.SVGGui.initiateBackgroundAnimation(SVGGui.java:82)
at gui.SVGGui.access$0(SVGGui.java:67)
at gui.SVGGui$1.gvtRenderingCompleted(SVGGui.java:42)
at org.apache.batik.swing.gvt.GVTTreeRenderer$4.dispatch(GVTTreeRenderer.java:193)
at org.apache.batik.util.EventDispatcher.dispatchEvent(EventDispatcher.java:103)
at org.apache.batik.util.EventDispatcher.fireEvent(EventDispatcher.java:87)
at org.apache.batik.util.EventDispatcher$1.run(EventDispatcher.java:46)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
This is quite strange because it says the xlink:href attribute is
missing, which is not true.
I'm using the current version of Batik available in the SVN branch
with Sun Java 6 on Windows Vista, coding with Eclipse Ganymede.
I hope somebody can help me.
Regards,
Julian
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Scripting Java: Error << The attribute "xlink:href" of the element
Posted by de...@googlemail.com.
Thank you very much, it works now.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Scripting Java: Error << The attribute "xlink:href" of the element
Posted by th...@kodak.com.
Hi Julian,
"Julian Petri" <de...@googlemail.com> wrote on 08/28/2008 05:04:37 PM:
> I want to add a <use> element to my svg document by creating and
> adding it to the DOM with Java. Here's the code:
>
> qm.setAttributeNS(null, "xlink:href", "#QuestionMark");
You need to pass the xlink namespace URI as the first argument
to setAttributeNS here:
String xlinkNS = "http://www.w3.org/1999/xlink";
qm.setAttributeNS(xlinkNS, "xlink:href", "#QuestionMark");
> This is quite strange because it says the xlink:href attribute is
> missing, which is not true.
Actually it is missing since xlink:href is a 'short hand' for the
href attribute in the xlink namespace.