KE Gan wrote:

(2) Use the inherited org.w3c.dom.Element.getElementByTagName() to get
the list of nodes with the same tag name.

You probably need to use the 'getElementByTagNameNS' calls and use the SVG Namespace to find SVG elements.

(3) Use the org.w3c.dom.Element.getElementByTagName(), then use cast
the node to the appropriate class. Eg,

NodeList list = root.getElementsByTagName("rect");

Same comment on namespace stuff...

for(int i = 0; i < list.getLength(); i++) {

SVGRectElement rect = (SVGRectElement)list.item(i);

Yup!

Still ... must I type the string "rect" at --
root.getElementsByTagName("rect"); -- Is there a string constant I can
refer somewhere ?

Batik has a bunch of constants classes you can use: org.apache.batik.util.SVGConstants XMLConstants CSSConstants

  The SVGConstants class has constants for all of the SVG elements
(as well as the SVG Namespace).

(4) By the way, what is the different between SVGRect and SVGRectElement ?

SVGRect is used for things like bounding boxes and has no element/node that participates in the DOM tree. The SVGRectElement is the DOM representation of an SVG 'rect' element.

(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 ?

Well it's not like the cast 'changes' the doc it's just going from a baseclass to a subclass. As Tonny mentioned there are interfaces on the SAXSVGDocumentFactory that return an SVGDocument. The DOM is quite font of returning baseclasses and requiring downcasting.


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



Reply via email to