0

I am trying to get the value of a node from third party source. Part of the Xmlstructure has a node whose name changes between, point and framedPoint. how do I get the latitude value?? here is part of the xml, their are many levels to the xml so have shown the relevant area.

here node is called point

 <tpegpointLocation xsi:type="TPEGSimplePoint">
     <point xsi:type="TPEGJunction">
         <pointCoordinates>
            <latitude>54.894825</latitude>
         </pointCoordinates>
     </point>
 </tpegpointLocation>

here framedPoint

<tpegpointLocation xsi:type="TPEGSimplePoint">
    <framedPoint xsi:type="TPEGJunction">
            <pointCoordinates>
                  <latitude>54.894825</latitude>
            </pointCoordinates>
    </framedPoint>
</tpegpointLocation>

Thanks, for any help

user2247671
  • 243
  • 1
  • 5
  • 14

2 Answers2

0

You could use asterisk as a wildcard in your xpath

/tpegpointLocation/*/pointCoordinates/latitude
Jirka Š.
  • 3,388
  • 2
  • 15
  • 17
  • didnt realise that at the * node, a nod call "to" exists and that has the same structure. It doesn't seem possible to use mix the wild card with point ie *oint? – user2247671 Oct 03 '13 at 12:00
  • No in this way; but you could use `*[ends-with(name(),'oint')]` – Jirka Š. Oct 03 '13 at 12:07
  • should have mentioned that the xml has a namespace, so my xpath each node looks like /x:latitude, .net now erroring and asking for XsltContext is needed?? – user2247671 Oct 03 '13 at 12:19
  • I don't know .net in much detail but it seems to be necessary to define appropriate prefix? Might be following could help: http://stackoverflow.com/questions/2311526/namespace-manager-or-xsltcontext-needed – Jirka Š. Oct 03 '13 at 12:24
0

The following XPath would do the job:

//tpegpointLocation//pointCoordinates/latitude

Which means:

  • //tpegpointLocation search for all <tpegpointLocation> elements in the XML file
  • The second //pointCoordinates means search for all <pointCoordinates> elements below <tpegpointLocation> regardless which elements are between them (one or more or different names
  • /latitude means get the <latitude> element below <pointCoordinates>

Please note that using // scans whole XML file. If you are able to change //tpegpointLocation it would be better and faster.

Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66