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

Thomas DeWeese <[email protected]>
Newsgroups gmane.text.xml.batik.user
Message-ID <CACTtnu3nuF7NPRf6_2aYz32OTnqfukSMtTAinzEw27wrCFHeOw@mail.gmail.com>
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]> 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]
>    Tel.     +31 (0)20 5987114
>    Fax.     +31 (0)20 5987112
>
> *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
>
>
>
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.