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.

 <ObservatoryLocation xlink:type="simple" xlink:href="ivo://STClib/Observatories#GEOLUN/" id="GEOLUN"/>
 <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">
<Position2D unit="deg">
 <Description>The RA,Dec coordinates are of the type: source_object.</Description>

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

Recommended Answers

All 4 Replies

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

      <AstroCoords coord_system_id="UTC-FK5-GEO">
        <Position2D unit="deg">

You're probably right, the XPATH should be:


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="" version="1.1" role="observation" ivorn="ivo://nasa.gsfc.gcn/SWIFT#BAT_GRB_Pos_512035-500" xmlns:xsi="" xmlns:xlink="" xsi:schemaLocation="">

And the Java script deals with it this way:

XmlDoc.setProperty("SelectionNamespaces", "xmlns:z=''");

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="">

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=''");

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 now that line looks like:

XmlDoc.setProperty("SelectionNamespaces", "xmlns:z='' xmlns:y=''");

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

<ObsDataLocation xmlns="">

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!

commented: Thanks for sharing. +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.