Hi Nierop, I'm fairly sure that the problem is that you haven't booted the SVG DOM. Please see the following link for information on how to do that:
http://wiki.apache.org/xmlgraphics-*batik*/BootSvgAndCssDom On Thu, Nov 22, 2012 at 3:04 AM, Nierop, P. van <p.van.nie...@vu.nl> wrote: > My next goal is to read in this svg file and generate a object > representation of the path element (try to make it a valid SVGOMPathElement > instance) This is the java code with which I try to read the svg: > > import java.io.File; > import java.io.IOException; > import java.net.URI; > import org.apache.batik.dom.svg.SAXSVGDocumentFactory; > import org.apache.batik.dom.svg.SVGOMPathElement; > import org.apache.batik.util.XMLResourceDescriptor; > import org.w3c.dom.Element; > import org.w3c.dom.svg.SVGDocument; > > public class TestSVGDomParser { > > public static void main(String[] args) throws IOException { > > URI fileURI = new File("basedrawing.svg").toURI(); > > String parser = XMLResourceDescriptor.getXMLParserClassName(); > SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); > SVGDocument doc = (SVGDocument) f.createDocument( > fileURI.toString() ); > > // try to get a path using the unique identifier > Element e = doc.getElementById("test"); > > // cast to path > SVGOMPathElement path = (SVGOMPathElement) e; > > // works fine > System.out.println( path.getAttribute("d") ); > > // does not work, throws a null pointer exception > System.out.println( path.getTotalLength() ); > } > > } > > The problem I think is that the cast of the e (instance of Element) to > path (instance of SVGOMPathElement) does not trigger the internal > interpretation of the 'd' attribute. I conclude from this that I do not > follow the proper procedures to build the object representation of the svg > document. > > Could someone advise me on how to proceed? > > Thanks in advance, > > Pim > > > -- > > *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > Pim van Nierop > > Center for Neurogenomics and Cognitive Research > Faculty of Earth and Life Sciences > Vrije Universiteit > Amsterdam > Email pim.van.nie...@cncr.vu.nl > Tel. +31 (0)20 5987114 > Fax. +31 (0)20 5987112 > > *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- > > >