Interrogation d’un fichier hprimXML avec R via xpath

Author

gpr

Published

August 17, 2024

library(xml2)
library(dplyr, warn.conflicts = FALSE)
f <- './../data/xml_tests/actes/00001.xml'
one_xml <- function(file_f) {
  u1 <- xml2::read_xml(file_f) %>% xml_ns_strip()
  
  ipp               <- u1 %>% xml_find_all(xpath = ".//evenementServeurActe/patient/identifiant/emetteur/valeur/text()") %>% xml_text()
  iep               <- u1 %>% xml_find_all(xpath = ".//evenementServeurActe/venue/identifiant/emetteur/valeur/text()") %>% xml_text()
  date_intervention <- u1 %>% xml_find_all(xpath = ".//evenementServeurActe/intervention/debut/*") %>% xml_text() %>% paste(collapse = " ")
  ccam_acte         <- u1 %>% xml_find_all(xpath = ".//evenementServeurActe/actesCCAM/acteCCAM/codeActe") %>% xml_text() %>% paste(collapse = ", ")  
  unites            <- u1 %>% xml_find_all(xpath = ".//evenementServeurActe/intervention/uniteFonctionnelle") %>% xml_text() %>% paste(collapse = ", ")

  tibble(message = basename(file_f), ipp = ipp, iep = iep, date_intervention = date_intervention, ccam_acte = ccam_acte, uf = unites)
}
one_xml(f)
A tibble: 1 × 6
message ipp iep date_intervention ccam_acte uf
<chr> <chr> <chr> <chr> <chr> <chr>
00001.xml 123456789 987654321 2024-01-01 08:10:00 EBLA003, YYYY033, EPLF002, NFKA006 4321