Hi Marco,

        Replies inline below...

On Jun 21, 2012, at 9:28 AM, m...@mherrn.de wrote:

> I am searching for a way to create SVG Elements that provide higher
> level methods for setting values.
> 
> For example an SVG rect element is represented by the interface
> SVGRectElement. This interface provides "higher level" methods to
> access its attributes, for example:
> * getX()
> * getY()
> * getWidth()
> * getHeight()
> 
> This is quite fine when trying to access existing SVG elements (by
> just casting it to the relevant Interface). But what if I need to
> _create_ such elements? The (uncomfortable and not very typesafe)
> way is by creating an org.w3c.dom.Element:
> 
> -------------------------/--------------------------
> final Element element= document.createElement("rect");
        
        This creates a 'rect' element in the no name namespace.
I think you want to use createElementNS with the SVG Namespace.
If you are using a Batik SVGDocument then this will return an
SVGRectElement.  Make sure you read about booting the CSS and
SVG DOM on the Wiki, otherwise some of the more advanced SVG
methods won't work (also the element needs to be part of the SVG 
tree for some of those methods to work).

> element.setAttribute("x", "10");
> element.setAttribute("y", "10");
> element.setAttribute("width", "100");
> element.setAttribute("height", "100");
> document.getDocumentElement().appendChild(element);
> -------------------------/--------------------------
> 
> What I am searching for is a way to create a rect like this:
> 
> -------------------------/--------------------------
> final SVGRect rectElement= ..... //create the element
> rectElement.setX(10);
> rectElement.setY(10);
> rectElement.setWidth(100);
> rectElement.setHeight(100);
> document.getDocumentElement().appendChild(rectElement);
> -------------------------/--------------------------
> 
> The interface SVGRect provides the methods I want to use.
> SVGSVGElement provides the method createSVGRect():SVGRect
> Unfortunately this SVGRect doesn't implement SVGRectElement, so adding
> this to the DOM via appendChild() leads to an exception.
> 
> I also found the class org.apache.batik.dom.svg.SVGOMRectElement,
> but have no idea what this is used for. Anyway, this class also
> only has getters, but no setters. Therefore is of no use for me.
> 
> Also there is the class
> org.apache.batik.dom.svg.SVGDOMImplementation.RectElementFactory.
> However, it is protected and can therefore not be used by me.
> 
> So what should I do? Is there a way to convert an instance of an SVGRect
> to an SVGRectElement? Is there another way have these
> convenient-methods for setting attributes to specific SVG element types?
> 
> Regards
> Marco
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org
> 


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

Reply via email to