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 Th...@blum.com on 2007/03/14 10:57:00 UTC

xlink:href

Hello,

I have a problem displaying SVGDocuments with an embedded image in a 
JSVGCanvas.

I have the following code which creates the SVGDocument with an image 
embbed in it.

DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
SVGDocument document = (SVGDocument) 
impl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);
Element svgRoot = document.getDocumentElement();

BufferedImage image = ImageIO.read(file);
ImageProcessor ip = new ImageProcessor(image, "jpeg");

svgRoot.setAttributeNS(null, SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + 
image.getWidth() + " " + image.getHeight());
svgRoot.setAttributeNS(null, "width", String.valueOf(image.getWidth()));
svgRoot.setAttributeNS(null, "height", String.valueOf(image.getHeight()));
Element imageElement = 
document.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "image");
imageElement.setAttributeNS(null, "x", "0");
imageElement.setAttributeNS(null, "y", "0");
imageElement.setAttributeNS(null, "width", 
String.valueOf(image.getWidth()) + "px");
imageElement.setAttributeNS(null, "height", 
String.valueOf(image.getHeight()) + "px");
imageElement.setAttributeNS(null, "xlink:href", "data:image/jpg;base64," + 
Base64.encode(ip.getImageAsByteArray()));
svgRoot.appendChild(imageElement);

The problem is that if I try to load this document in an JSVGCanvas (with 
the setDocument() method) I get and error message and the following 
exception.

org.apache.batik.bridge.BridgeException: null:-1
The attribute "xlink:href" of the element <image> is required
        at 
org.apache.batik.bridge.SVGImageElementBridge.buildImageGraphicsNode(Unknown 
Source)
        at 
org.apache.batik.bridge.SVGImageElementBridge.createGraphicsNode(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown 
Source)
        at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
        at org.apache.batik.swing.svg.GVTTreeBuilder.run(Unknown Source)

The funny thing is that if I fist save the document to a file and create a 
document with the SAXSVGDocumentFactory the file works perfectly. Am I 
missing something?

kind regards
Thomas

Re: xlink:href

Posted by Steffen Jacobs <sj...@informatik.uni-kiel.de>.
Hello there,

after a brief look, I think it should be
imageElement.setAttributeNS(xlinkNS, "href", ...);

Regards,
Steffen Jacobs

> Hi,
>
> On Wed, 2007-03-14 at 10:57 +0100, Thomas.Hagen@blum.com wrote:
>   
>> Hello, 
>>
>> I have a problem displaying SVGDocuments with an embedded image in a
>> JSVGCanvas. 
>>
>> imageElement.setAttributeNS(null, "xlink:href",
>> "data:image/jpg;base64," + Base64.encode(ip.getImageAsByteArray())); 
>> svgRoot.appendChild(imageElement); 
>>     
>
> Have you try
> String xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
> imageElement.setAttributeNS(xlinkNS,"xlink:href",....)
>
> on the namespace part use the xlink namespace not null.
>
> Regards
> Tonny Kohar
>   


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


Antwort: Re: xlink:href

Posted by Th...@blum.com.
Hi again,

I tried it with setting the namespace to "http://www.w3.org/1999/xlink". 
(I couldn't find a constant in the XMLConstants class for this one).

This works! 

So I need the xlink namespace (which seems logical *g*).

However thanks for your help!

Gruß
Thomas



Tonny Kohar <to...@kiyut.com> 
14.03.2007 15:33
Bitte antworten an
batik-users@xmlgraphics.apache.org


An
batik-users@xmlgraphics.apache.org
Kopie

Thema
Re: xlink:href






Hi,

On Wed, 2007-03-14 at 10:57 +0100, Thomas.Hagen@blum.com wrote:
> 
> Hello, 
> 
> I have a problem displaying SVGDocuments with an embedded image in a
> JSVGCanvas. 
> 
> imageElement.setAttributeNS(null, "xlink:href",
> "data:image/jpg;base64," + Base64.encode(ip.getImageAsByteArray())); 
> svgRoot.appendChild(imageElement); 

Have you try
String xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
imageElement.setAttributeNS(xlinkNS,"xlink:href",....)

on the namespace part use the xlink namespace not null.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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



Antwort: Re: Antwort: Re: xlink:href

Posted by Th...@blum.com.
Ah you're right I used the wrong XMLContants class. 

Nonetheless the value of XMLConstants.XLINK_NAMESPACE_URI is 
http://www.w3.org/XML/1998/namespace but the value I need is 
http://www.w3.org/1999/xlink.

Regards
Thomas



Tonny Kohar <to...@kiyut.com> 
14.03.2007 20:45
Bitte antworten an
batik-users@xmlgraphics.apache.org


An
batik-users@xmlgraphics.apache.org
Kopie

Thema
Re: Antwort: Re: xlink:href






Hi,

On Wed, 2007-03-14 at 16:02 +0100, Thomas.Hagen@blum.com wrote:
> 
> Hi, 
> 
> I tried it with XMLConstants.XML_NS_URI (which I think is what you
> meant, because I could not find a constant
> namedXMLConstants.XLINK_NAMESPACE_URI) but it had no effect. The error
> still occurs. 
> 
I do not know which version of batik you are using, but on my batik
source there is at org.apache.batik.util.XMLConstants around line 32.

Please do not be confused with the java XMLConstants it self in
javax.xml.XMLConstants and batik supplied
org.apache.batik.util.XMLConstants

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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



Re: Antwort: Re: xlink:href

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Wed, 2007-03-14 at 16:02 +0100, Thomas.Hagen@blum.com wrote:
> 
> Hi, 
> 
> I tried it with XMLConstants.XML_NS_URI (which I think is what you
> meant, because I could not find a constant
> namedXMLConstants.XLINK_NAMESPACE_URI) but it had no effect. The error
> still occurs. 
> 
I do not know which version of batik you are using, but on my batik
source there is at org.apache.batik.util.XMLConstants around line 32.

Please do not be confused with the java XMLConstants it self in
javax.xml.XMLConstants and batik supplied
org.apache.batik.util.XMLConstants

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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


Antwort: Re: xlink:href

Posted by Th...@blum.com.
Hi,

I tried it with XMLConstants.XML_NS_URI (which I think is what you meant, 
because I could not find a constant named XMLConstants.XLINK_NAMESPACE_URI
) but it had no effect. The error still occurs.

Regards
Thomas



Tonny Kohar <to...@kiyut.com> 
14.03.2007 15:33
Bitte antworten an
batik-users@xmlgraphics.apache.org


An
batik-users@xmlgraphics.apache.org
Kopie

Thema
Re: xlink:href






Hi,

On Wed, 2007-03-14 at 10:57 +0100, Thomas.Hagen@blum.com wrote:
> 
> Hello, 
> 
> I have a problem displaying SVGDocuments with an embedded image in a
> JSVGCanvas. 
> 
> imageElement.setAttributeNS(null, "xlink:href",
> "data:image/jpg;base64," + Base64.encode(ip.getImageAsByteArray())); 
> svgRoot.appendChild(imageElement); 

Have you try
String xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
imageElement.setAttributeNS(xlinkNS,"xlink:href",....)

on the namespace part use the xlink namespace not null.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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



Re: xlink:href

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

On Wed, 2007-03-14 at 10:57 +0100, Thomas.Hagen@blum.com wrote:
> 
> Hello, 
> 
> I have a problem displaying SVGDocuments with an embedded image in a
> JSVGCanvas. 
> 
> imageElement.setAttributeNS(null, "xlink:href",
> "data:image/jpg;base64," + Base64.encode(ip.getImageAsByteArray())); 
> svgRoot.appendChild(imageElement); 

Have you try
String xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
imageElement.setAttributeNS(xlinkNS,"xlink:href",....)

on the namespace part use the xlink namespace not null.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


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