Created
February 16, 2018 22:03
-
-
Save csjx/7e61d207d37ab56b07193f69c5d5de02 to your computer and use it in GitHub Desktop.
Filters the DataONE node list to extract certain node properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(xml2) | |
library(httr) | |
# Get the XML from the CN | |
nodes_xml <- GET("https://cn.dataone.org/cn/v2/node") | |
# Build an xml document object | |
node_document <- read_xml(nodes_xml) | |
# Filter out CNs and dedicated replica MNs | |
filtered_node_list <- xml_find_all(node_document, "//node[@type='mn' and not(starts-with(identifier, 'urn:node:mn'))]") | |
count = 0 | |
for (node in filtered_node_list) { | |
count = count + 1 | |
node_id <- xml_text(xml_find_all(node, "identifier")) | |
node_name <- xml_text(xml_find_all(node, "name")) | |
node_date_operational <- xml_text(xml_find_all(node, "property[@key='CN_date_operational']")) | |
node_lon_lat <- xml_text(xml_find_all(node, "property[@key='CN_location_lonlat']")) | |
print(paste0(count, ")")) | |
print(node_id) | |
print(node_name,) | |
print(node_date_operational) | |
print(node_lon_lat) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment