You're going to need to use the xlink namespace, not null for xlink attributes. 
 This is quietly "fixed" when saving/loading from a document which is why it 
works when you do that.

Michael Bishop



From: Qian Li
Sent: Mon 2/4/2008 3:34 PM
To: batik-users
Subject: Loading an Image into JSVGCanvas using SVG Image tag


Hello, everyone,

I want to load an image into JSVGCanvas, however I always get following error:
"SVG Error:

null:-1
The attribute "xlink:href" of the element <image> is required"

And the image does not display at all. My java code is as following:
String svgNS = SVG12DOMImplementation.SVG_NAMESPACE_URI;
Element icon = svgDoc.createElementNS(svgNS, SVGConstants.SVG_IMAGE_TAG);
icon.setAttributeNS(null, SVGConstants.XLINK_HREF_QNAME, iconPath);
icon.setAttributeNS(null, SVGConstants.SVG_WIDTH_ATTRIBUTE, "100");
icon.setAttributeNS(null, SVGConstants.SVG_HEIGHT_ATTRIBUTE, "100");
icon.setAttributeNS(null, SVGConstants.SVG_X_ATTRIBUTE, "30");
icon.setAttributeNS(null, SVGConstants.SVG_Y_ATTRIBUTE, "30");
svgRoot.appendChild(icon);

If I save the generated SVG code into a file, and load that file, I
can see my image without any problem.

If I do the following changes to the code, I do not have the exception
anymore, however my image become a broken link icon.
String xlinkNS = SVGConstants.XLINK_NAMESPACE_URI;
icon.setAttributeNS(xlinkNS, SVGConstants.XLINK_HREF_QNAME, iconPath);

If I save the generated SVG code into a file, and load that file, I
still can see my image without any problem.

Does anyone know what maybe the problem causing this? Is this a known
bug in Batik or I'm doing something wrong?
Thanks.

Kind regards,
Qian

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to