[AstroPy] saving a votable as a xml file using astropy

Susana Sanchez susanasanche at gmail.com
Mon Feb 25 12:46:57 EST 2013

Hi again,

This time I have the doubt saving votables as xml. As I said in my
previous mail, I want to show the VOTable in a nice way using Qt
library, I also want to allow the users can modify this votable and
then save the changes.

Reading the documentation I saw that the astropy.io.votable.tree.Table
has the method .to_xml, but probably I am not using it  well because I
get this error:

In [159]: table =
In [160]: table.to_xml("./cig22_changed.xml")
AttributeError                            Traceback (most recent call last)

/home/susana/<ipython console> in <module>()

/usr/local/lib/python2.6/dist-packages/astropy/io/votable/tree.pyc in
to_xml(self, w, **kwargs)
   2519     def to_xml(self, w, **kwargs):
-> 2520         with w.tag(
   2521             u'TABLE',
   2522             attrib=w.object_attrs(

AttributeError: 'str' object has no attribute 'tag'

Finally I got this way to save the xml:

#Open the votable
table = astropy.io.votable.parse_single_table("/home/susana/Documents/guipsy/examples/tables/cig22.xml",pedantic=False)

#Modify the table
table.array['CIG Number'][0]="CIG SUSANA"

#Create a VOTableFile instance of the table
votable= VOTableFile.from_table(table.to_table())

#Save the xml

I have two questions/comments:

1) Is this way correct? Or maybe there is a better way to save the
changes made in a VOtable?

2) The VOTable created,  'cig22S.xml', is ok, but the fields have lost
the 'name' value. Now, the 'ID' and the 'name' have the same value
(the original value of ID).

Thanks again,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cig22.xml
Type: text/xml
Size: 11381 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20130225/7e038803/attachment.xml>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cig22S.xml
Type: text/xml
Size: 10865 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20130225/7e038803/attachment-0001.xml>

More information about the AstroPy mailing list