Please see attached XML file.

I am using the XPATH expression getValueXPath() in JavaScript to extract one value from an XML alert message - to control a robotic telescope.

I need to extract the value for Dec, a coordinate location in the sky that is a child of <WhereWhen>

The particular value I need to retrieve is green/bold in the below excerpt.

<WhereWhen>
<ObsDataLocation>
 <ObservatoryLocation xlink:type="simple" xlink:href="ivo://STClib/Observatories#GEOLUN/" id="GEOLUN"/>
<ObservationLocation>
 <AstroCoordSystem xlink:type="simple" xlink:href="ivo://STClib/CoordSys#UTC-FK5-GEO/" id="UTC-FK5-GEO"/>
<AstroCoords coord_system_id="UTC-FK5-GEO">
<Time unit="s">
<TimeInstant>
 <ISOTime>2012-01-19T04:04:30.21</ISOTime>
 </TimeInstant>
 </Time>
<Position2D unit="deg">
 <Name1>RA</Name1>
 <Name2>Dec</Name2>
<Value2>
 <C1>120.0271</C1>
 [B]<C2>-9.0739</C2>[/B]
 </Value2>
 <Error2Radius>0.0500</Error2Radius>
 </Position2D>
 </AstroCoords>
 </ObservationLocation>
 </ObsDataLocation>
 <Description>The RA,Dec coordinates are of the type: source_object.</Description>
 </WhereWhen>

I have tried many variations on this expression, but have not been able to extract the value

dec = getValueXPath(XmlDoc, '/z:VOEvent/WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/Position2D/Dec');

What is the correct XPATH for this particular file and format?

Thank you in advance,
Tom Krajci

Looks like it should end with this /Position2D/Value2/C2 (Based on this)

<WhereWhen>
  <ObsDataLocation>
    <ObservationLocation>
      <AstroCoords coord_system_id="UTC-FK5-GEO">
        <Position2D unit="deg">
          <Value2>
            <C2>-9.0739</C2>

Edited 4 Years Ago by pritaeas: n/a

You're probably right, the XPATH should be:

/z:VOEvent/WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/Position2D/Value2/C2

But it appears that XML namespaces are an important factor here.

At the root of the XML file I attached in the first post, we have

<voe:VOEvent xmlns:voe="http://www.ivoa.net/xml/VOEvent/v1.1" version="1.1" role="observation" ivorn="ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_512035-500" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.ivoa.net/xml/VOEvent/v1.1 http://www.ivoa.net/xml/VOEvent/VOEvent-v1.1.xsd">

And the Java script deals with it this way:

XmlDoc.setProperty("SelectionNamespaces", "xmlns:z='http://www.ivoa.net/xml/VOEvent/v1.1'");

That works well for 'shallow' XPATH queries, but for my 'deep' query, I see that a new XML namespace is provided when we get down to <ObsDataLocation>

<ObsDataLocation xmlns="http://www.ivoa.net/xml/STC/stc-v1.30.xsd">

What does the XPATH look like when we have one xmlns in the root, and another xmlns down lower?

I think you should just add it like the other one, and apply it where needed (like the z: prefix in your example).

Thank you!

If anyone is interested, below are the dirty details I learned and implemented.

Original version of the filter script uses only one (the default value) xml namespace:

XmlDoc.setProperty("SelectionNamespaces", "xmlns:z='http://www.ivoa.net/xml/VOEvent/v1.1'");

That's fine for 'shallow' searches in the Swift GRB XML files, but the value for declination is 'deep' in the XML tree, and you need to identify another xml namespace...so now that line looks like:

XmlDoc.setProperty("SelectionNamespaces", "xmlns:z='http://www.ivoa.net/xml/VOEvent/v1.1' xmlns:y='http://www.ivoa.net/xml/STC/stc-v1.30.xsd'");

because if you look at this node: <ObsDataLocation> ...it lists a new namespace:

<ObsDataLocation xmlns="http://www.ivoa.net/xml/STC/stc-v1.30.xsd">

It's not an elegant solution, but I created a javascript function:

function getDecValue(XmlDoc)
{
    return getValueXPath(XmlDoc, '/z:VOEvent/WhereWhen/y:ObsDataLocation/y:ObservationLocation/y:AstroCoords/y:Position2D/y:Value2/y:C2');
}

note that the new namespace is called/referenced with y: ....and I had to add it for every child/level....down to the final node. Whew!

But now, I get this result with a test GRB message that's south of +20 declination:


22-Jan-2012 16:28:50.6: NEW MESSAGE (Observation): ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_2012-01-22T16:28:20_879862-0
22-Jan-2012 16:28:50.6: Filtering...
22-Jan-2012 16:28:50.7: ...rejected by filter with explanation:
22-Jan-2012 16:28:50.7: A SWIFT/GRB BAT_GRB_Pos alert with declination 15.0001 degrees was received and discarded.

In other words it's now working the way I want it.

Thank you again!

Comments
Thanks for sharing.
This question has already been answered. Start a new discussion instead.