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

Susana Sanchez susanasanche@gmail....
Mon Feb 25 11:46:57 CST 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 =
parse_single_table("/home/susana/Documents/guipsy/examples/tables/cig22.xml",pedantic=False)
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)
   2518
   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
votable.to_xml('cig22S.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,
Susana.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cig22.xml
Type: text/xml
Size: 11380 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/astropy/attachments/20130225/7e038803/attachment-0002.xml 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cig22S.xml
Type: text/xml
Size: 10864 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/astropy/attachments/20130225/7e038803/attachment-0003.xml 


More information about the AstroPy mailing list