Hi, 
> I want to manipulate a SVG document (loaded from a file) using Batik's
> SVG DOM api (org.apache.batik.dom.svg).
> 
> 
> (1) The sample in Batik's website show that to get a SVGDocument
> instance, I have to cast from a org.w3c.dom.Document, which in turn I
> obtain from SAXSVGDocumentFactory.
> 
> String parser = XMLResourceDescriptor.getXMLParserClassName();
> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
> InputStream is = new FileInputStream("svgdom\\resource\\sample.svg");
> Document doc = f.createDocument(null, is);
> SVGDocument svgDoc = (SVGDocument)doc;
> 
> Is this the most appropriate way ? Can I load a SVG file (into
> SVGDocument) without using org.w3c.dom.Document as the medium ?

I think this is the correct way, or you can use
f.createSVGDocument(param....) which will return SVGDocument (no need to
cast). The factory createDocument method is exist because it inherit
from its parent which is just generic XML Document Factory.

> (2) To navigate the SVG DOM, I started by calling
> SVGDocument.getRootElement(), which return a SVGSVGElement. To get the
> list of children nodes from this root, I use the inherited
> org.w3c.dom.Node.getChildNodes().
> 
> NodeList nodeList = svgDoc.getRootElement().getChildNodes();
> 
> Is this the right way go get a list of children nodes ? Is there a SVG
> DOM specific API for getting the list of children nodes ? Maybe if I
> only want to get children that are SVGRect element ?

There are many way to navigate SVG DOM:
- use Standard DOM API (getChildNode, getElementById, etc ...)
- use DOM Traversal
- use XPATH ??? does batik support this?

> 
> (3) To know which node represents what SVG element. I use the
> inherited org.w3c.dom.Node.getNodeName(), and compare with strings
> such as "path", "polyline", etc. Again, is the correct way ? Is there
> a SVG DOM api that can achive the same effect without comparing each
> strings ? Maybe a .isPath() method, for example.

You also can use java instanceof eg:
if (node instaceof SVGRectElement) etc

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


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

Reply via email to