RE: Parsing SVG in python
"Pranav Lal" <[email protected]> Tue, 14 Jan 2014 12:12:55 +0530
| Newsgroups | gmane.text.xml.svg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Björn,
Many thanks. Your reference to lxml did the trick. Here is my code. It is a
work in progress. I am storing all coordinates of lines and rectangles in a
python list.
import numpy as np
from lxml import etree
filename='plan.svg'
tree = etree.parse(open(filename, 'r'))
#mega list of all coordinates
allPoints=[]
for element in tree.iter():
cleanTag=element.tag.split("}")[1]
#handle a rectangle and a line
if cleanTag=='line' or cleanTag=='rect':
x1=element.get('x1')
x2=element.get('x2')
y1=element.get('y1')
y2=element.get('y2')
allPoints.append(x1)
allPoints.append(y1)
allPoints.append(x2)
allPoints.append(y2)
for item in allPoints:
print item
Pranav
-----Original Message-----
From: [email protected] [mailto:[email protected]]
On Behalf Of Bjoern Hoehrmann
Sent: Tuesday, January 14, 2014 12:36 AM
To: [email protected]
Subject: Re: [svg-developers] Parsing SVG in python
* Pranav Lal wrote:
>try:
> import xml.etree.cElementTree as ET
>except ImportError:
> import xml.etree.ElementTree as ET
>
>tree = ET.ElementTree(file='plan.svg')
>root=tree.getroot()
>
>for elem in tree.iter(tag='rect'):
> print elem.tag, elem.attrib
You probably need to read up on namespace usage in ElementTree, e.g.
http://stackoverflow.com/questions/14853243/ has some information.
--
Björn Höhrmann · mailto:[email protected] · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
------------------------------------
-----
To unsubscribe send a message to: [email protected]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my membership"
----Yahoo Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/svg-developers/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/svg-developers/join
(Yahoo! ID required)
<*> To change settings via email:
[email protected]
[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo Groups is subject to:
http://info.yahoo.com/legal/us/yahoo/utos/terms/