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 Qian Li <qi...@googlemail.com> on 2008/02/04 21:34:03 UTC

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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Loading an Image into JSVGCanvas using SVG Image tag

Posted by Qian Li <qi...@googlemail.com>.
Thank you very much for your replay.

I have found the solution. When I setting the iconPath, I used the
fixed String path, e.g. /home/user/icon.gif.
The SVGConstants.XLINK_HREF_QNAME is really looking for URI path, so
when I convert my file path to URI, then it solved the problem.

Kind regards,
Qian


On Feb 5, 2008 2:40 PM, Bishop, Michael W. CONTR J9C880
<Mi...@je.jfcom.mil> wrote:
>
>
>
> 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: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Loading an Image into JSVGCanvas using SVG Image tag

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org