I think I am going to answer some of my own questions B-) Just happen to understand more today.
(2) Use the inherited org.w3c.dom.Element.getElementByTagName() to get the list of nodes with the same tag name. (3) Use the org.w3c.dom.Element.getElementByTagName(), then use cast the node to the appropriate class. Eg, NodeList list = root.getElementsByTagName("rect"); for(int i = 0; i < list.getLength(); i++) { SVGRectElement rect = (SVGRectElement)list.item(i); // do something useful with - rect - } Still ... must I type the string "rect" at -- root.getElementsByTagName("rect"); -- Is there a string constant I can refer somewhere ? (4) By the way, what is the different between SVGRect and SVGRectElement ? ** Please comment on question (1), and the rest as well if required ? Thanks. ~KEGan On Tue, 8 Mar 2005 01:09:11 +0800, KE Gan <[EMAIL PROTECTED]> wrote: > 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 ? > > (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 ? > > (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. > > ** Obviously I am new to XML, SVG and Batik. Thanks you in advance for > answering these basic questions :) ** > > Thanks. > > ~KEGan > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]