RE: Problem using path objects (SVGOMPathElement) parsed from svg file

"Nierop, P. van" <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <[email protected]>
Thanks a lot! This was the information that I missed.

All the best,

Pim

--
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

   Pim van Nierop

   Center for Neurogenomics and Cognitive Research
   Faculty of Earth and Life Sciences
   Vrije Universiteit
   Amsterdam
   Email    [email protected]
   Tel.     +31 (0)20 5987114
   Fax.     +31 (0)20 5987112

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

________________________________
From: Thomas DeWeese [[email protected]]
Sent: 24 November 2012 13:14
To: [email protected]
Subject: Re: Problem using path objects (SVGOMPathElement) parsed from svg file

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 <[email protected]<mailto:[email protected]>> 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    [email protected]<mailto:[email protected]>
   Tel.     +31 (0)20 5987114<tel:%2B31%20%280%2920%205987114>
   Fax.     +31 (0)20 5987112<tel:%2B31%20%280%2920%205987112>

*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.