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

Michael Droettboom mdroe@stsci....
Mon Feb 25 12:00:21 CST 2013


VOTable is actually a container format for multiple tables, so you can 
only save that entire container to XML.

The best thing to do to make modifications to save back out would be to 
retain a reference to the top-level VOTableFile object (not the 
votable.tree.Table object), and call `to_xml` on that.  That approach 
should also maintain all of the metadata (what the original names and 
IDs were).

Hope that helps, and feel free to ping me if you need more detail.

Mike

On 02/25/2013 12:46 PM, Susana Sanchez wrote:
> 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.
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy@scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/astropy/attachments/20130225/6adda7bf/attachment.html 


More information about the AstroPy mailing list