Jul. 19, 2012

Parsing Inkscape/SVG files in PHP with XPath

So, you need a namespace. And this is a generic way to obtain and apply a namespace:

$doc = new DOMDocument();
$doc->loadXML( $variable0 );
$xpath = new DOMXPath($doc);
$rootNamespace = $doc->lookupNamespaceUri($doc->namespaceURI);
$xpath->registerNamespace('svg', $rootNamespace); 
$paths = @$xpath->query( "//svg:path");

Where $variable0 is the loaded SVG code.  At any rate, this thing here parses PATH objects in the SVG file.

Find this interesting, or useful? Consider sharing the post.

Leave a Reply

Your email address will not be published. Required fields are marked *

Posts on this blog solely represent my personal opinions and technical experience.

© 2009-2017 Edin (Dino) Beslagic