I have an XML file with measurements. I would like to select only those measurementSiteName's that have a latitude and longitude using R.
With this code chunk I can select the name of a site with a specific latitude:
doc <- xml2::read_xml('test.xml')
query <- ".//measurementSiteName/values/value[../../../measurementSiteLocation/locationForDisplay/latitude/text() = '52.23634']"
xml2::xml_text(xml2::xml_find_all(doc, query))
However, there are site names without a latitude or longitude. I don't know how to do this. The latitude and longitude nodes may be missing or empty.
Can somebody please help me out? Please find attached text.xml
<measurements>
<measurement>
<measurementSiteName>
<values>
<value>abc</value>
</values>
</measurementSiteName>
<measurementSiteLocation>
<locationForDisplay>
<latitude>52.23634</latitude>
<longitude>4.503404</longitude>
</locationForDisplay>
</measurementSiteLocation>
</measurement>
<measurement>
<measurementSiteName>
<values>
<value>def</value>
</values>
</measurementSiteName>
<measurementSiteLocation>
<locationForDisplay>
<latitude></latitude>
<longitude></longitude>
</locationForDisplay>
</measurementSiteLocation>
</measurement>
<measurement>
<measurementSiteName>
<values>
<value>ghi</value>
</values>
</measurementSiteName>
<measurementSiteLocation>
<locationForDisplay>
</locationForDisplay>
</measurementSiteLocation>
</measurement>
</measurements>