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 Gold Martin <Ma...@blva.bayern.de> on 2003/10/14 18:58:50 UTC

error with attribute 'xlink:href' when loading a raster image

hello,

I have written an Interactor to load raster images into the canvas.
When I click into the SVG-Canvas to load the raster image I get the
following error message:
The attribute 'xlink:href' of the element <image> is required


The header of my SVG-file looks like this:
<?xml version='1.0' standalone='no'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20001102//EN'
'http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd'>
<svg contentScriptType="text/ecmascript" width="700"
     xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
     contentStyleType="text/css" viewBox="4280000 -5620000 350000 400000"
     height="700" preserveAspectRatio="xMidYMid meet"
     xmlns="http://www.w3.org/2000/svg" version="1.0">
     ...


The code in the update queue of my interactor to show the raster image looks
like that:
    public void mousePressed(MouseEvent e) {
        final JSVGCanvas svgCanvas = (JSVGCanvas) e.getSource();          
        
        beendet = true;
        if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON1_MASK) !=
0)
        {
            try {
 
svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(
            new Runnable() {
               public void run() {
 
svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform());  
                  
                  final Document document = svgCanvas.getSVGDocument();
                  final Element svgRoot = document.getDocumentElement();
                  final String svgNS =
SVGDOMImplementation.SVG_NAMESPACE_URI;  
                  
                  Element gruppe = document.createElementNS(svgNS, "g"); 
                  gruppe.setAttributeNS(null, "id", svgCanvas.RASTER_ID);
                  gruppe.setAttributeNS(null, "transform", new String
("translate(4350366.25,-5365852.82)"));
                  gruppe.setAttributeNS(null, "visibility", "visible");
                  svgRoot.appendChild(gruppe);
                  Element image = document.createElementNS(svgNS, "image"); 
                  image.setAttributeNS(null, "xlink:href",
"resources/l7726col.gif");   
                  image.setAttributeNS(null, "x", new String ("0"));
                  image.setAttributeNS(null, "y", new String ("0"));
                  image.setAttributeNS(null, "width", "28117.8");
                  image.setAttributeNS(null, "height","26035.0");    
                  gruppe.appendChild(image);        
              }
            }); 
            } catch (Exception ex) {
                   ex.printStackTrace();
            }
        }
    }


You can see the xlink namespace in my document is declared.
So why do I get this error message ?
What I'm doing wrong ?

Best regards and thanks for your help,
Martin


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


Re: error with attribute 'xlink:href' when loading a raster image

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

instead of using this 
image.setAttributeNS(null, "xlink:href","resources/l7726col.gif");
see below.

quote from earlier mailing list message,
"Finally, for attributes which belong to a specific namespace, like
the the href attribute on the <image> element, you have to use the
setAttributeNS method with the XLink namespace. For example, assuming
img references an <image> DOM Element, you can modify the href as
follows:
   img.setAttributeNS(xlinkNS, "xlink:href", "myImage.jpg")

where xlinkNS is equal to "http://www.w3.org/1999/xlink"
"


Regards
Tonny Kohar
http://www.kiyut.com

On Tue, 2003-10-14 at 23:58, Gold Martin wrote:
> hello,
> 
> I have written an Interactor to load raster images into the canvas.
> When I click into the SVG-Canvas to load the raster image I get the
> following error message:
> The attribute 'xlink:href' of the element <image> is required
> 
> 
> The header of my SVG-file looks like this:
> <?xml version='1.0' standalone='no'?>
> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20001102//EN'
> 'http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd'>
> <svg contentScriptType="text/ecmascript" width="700"
>      xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
>      contentStyleType="text/css" viewBox="4280000 -5620000 350000 400000"
>      height="700" preserveAspectRatio="xMidYMid meet"
>      xmlns="http://www.w3.org/2000/svg" version="1.0">
>      ...
> 
> 
> The code in the update queue of my interactor to show the raster image looks
> like that:
>     public void mousePressed(MouseEvent e) {
>         final JSVGCanvas svgCanvas = (JSVGCanvas) e.getSource();          
>         
>         beendet = true;
>         if ((e.getModifiers() & java.awt.event.InputEvent.BUTTON1_MASK) !=
> 0)
>         {
>             try {
>  
> svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(
>             new Runnable() {
>                public void run() {
>  
> svgCanvas.setRenderingTransform(svgCanvas.getRenderingTransform());  
>                   
>                   final Document document = svgCanvas.getSVGDocument();
>                   final Element svgRoot = document.getDocumentElement();
>                   final String svgNS =
> SVGDOMImplementation.SVG_NAMESPACE_URI;  
>                   
>                   Element gruppe = document.createElementNS(svgNS, "g"); 
>                   gruppe.setAttributeNS(null, "id", svgCanvas.RASTER_ID);
>                   gruppe.setAttributeNS(null, "transform", new String
> ("translate(4350366.25,-5365852.82)"));
>                   gruppe.setAttributeNS(null, "visibility", "visible");
>                   svgRoot.appendChild(gruppe);
>                   Element image = document.createElementNS(svgNS, "image"); 
>                   image.setAttributeNS(null, "xlink:href",
> "resources/l7726col.gif");   
>                   image.setAttributeNS(null, "x", new String ("0"));
>                   image.setAttributeNS(null, "y", new String ("0"));
>                   image.setAttributeNS(null, "width", "28117.8");
>                   image.setAttributeNS(null, "height","26035.0");    
>                   gruppe.appendChild(image);        
>               }
>             }); 
>             } catch (Exception ex) {
>                    ex.printStackTrace();
>             }
>         }
>     }
> 
> 
> You can see the xlink namespace in my document is declared.
> So why do I get this error message ?
> What I'm doing wrong ?
> 
> Best regards and thanks for your help,
> Martin
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 


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