[AstroPy] getting id value from xml files
mdroe at stsci.edu
Wed Apr 1 08:46:47 EDT 2015
In the specific case of your file, the INFO elements are all at the top
level, so they can be obtained through the |.infos| member, e.g.:
|from astropy.io import votable
vot = votable.parse('file.xml')
def find_by_ID(vot, ID):
for info in vot.infos:
if info.ID == ID:
But, as I said, this functionality really should be built-in to astropy,
and PR https://github.com/astropy/astropy/pull/3633 adds this to master
(and it’s more general because it will search the entire file, not just
the INFO elements at the top-level).
On 03/31/2015 11:26 AM, Michael Droettboom wrote:
> On 03/29/2015 05:21 PM, Grigoris Maravelias wrote:
>> Hi Mike! I just found time to check it...
>> On 03/27/2015 02:43 PM, Michael Droettboom wrote:
>>> The you could do:
>>> |from astropy.io import votable
>>> vot = votable.parse("file.xml")
>>> value = vot.resources.infos.value|
>> |I tried that but returns an error:
>> |ERROR: IndexError: list index out of range [__main__]
>> Traceback (most recent call last):
>> File "./xml_extractor.py", line 21, in <module>
>> value = vot.resources.infos.value
>> IndexError: list index out of range|
> That was just an example if your file happened to have the same layout
> as what I suggested -- since I hadn't seen your file, I just had to
> guess. Chances are your INFO element in question is in a different
> location, so you'll need to adjust accordingly.
>>> I assume you are asking how to do this with astropy.io.votable?
>>> INFO tags can appear in a number of places in a VOTable file, so
>>> without seeing the whole file, it’s hard to say.
>>> For example, if you had a file like:
>>> <INFO ID="sfr" name="sfr" value="1.34267351483e-40"/>
>> You are almost correct. I provide an original xml file (see )
> I don't see the target of the citation (maybe just forgot?).
>> AstroPy mailing list
>> AstroPy at scipy.org
> AstroPy mailing list
> AstroPy at scipy.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the AstroPy