j.gooch
j.gooch

Reputation: 305

how do you parse shapes from an svg file with php and add select data to a database?

effectively what I am trying to do is pull the shape information from the svg file and store the shapes by id into a mysql database. since there are many tools available with php to read xml I converted the svg document to an xml document but unfortunately the shapes from the svg document are stored as attributes.

I attempted to use the attributes() method but no luck as I got the php error Fatal error: Call to a member function attributes() on a non-object in phpdocument.php when I tried to get the rect data from the (now) xml document the full xml document that I used for the example can be found here http://pastebin.com/ZyNB7yKu the initial xml attribute test code I used was this

 $xml_file_open = simplexml_load_file("svgboard.xml");
 foreach($xml_file_open->rect[0]->attributes() as $a => $b)
{
echo $a, '="',$b,"\"</br>";
}

Upvotes: 0

Views: 2351

Answers (1)

Woody
Woody

Reputation: 5130

Assuming you open the file correctly (I assume your file checking is removed for clarity), the rect you are looking for is inside the G element, so $xml_file_open->rect[0] doesn't exist. You probabaly want $xml_file_open->g->rect[0]

Upvotes: 1

Related Questions