ropensci / emld

:package: JSON-LD representation of EML
https://docs.ropensci.org/emld
Other
13 stars 6 forks source link

EML attributes dropped from tags silently #67

Open thesadie opened 4 years ago

thesadie commented 4 years ago

New to EML 2.2.0 is support for ids in taxonomicClassification

I want to be able to set the attributes of tags in order to include <taxonId> in taxonomic coverage. The attribute is dropped silently when i use emld::as_xml(). Is there a way to do this?

x <- read_xml("<taxonId>12345</taxonId>")
# {xml_document}
# <taxonId>
x

xml2::xml_set_attr(x, "provider", "ITIS")
# {xml_document}
# <taxonId provider="ITIS">
x

xml2::as_list(x) %>% 
  emld::as_xml()
# {xml_document}
# <eml xsi:schemaLocation="https://eml.ecoinformatics.org/eml-2.2.0 https://eml.ecoinformatics.org/eml-2.2.0/eml.xsd" xmlns:eml="https://eml.ecoinformatics.org/eml-2.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:stmml="http://www.xml-cml.org/schema/stmml-1.2">
# [1] <taxonId>12345</taxonId>
amoeba commented 4 years ago

Hey @thesadie, thanks for filing an issue. It's great that you're looking to use taxonomic IDs with your taxonomic coverage.

This package, emld, is an internal package used by the EML package which is what we have built for scientists & other users. Do you have a use case where you need to use emld directly? Normally, we'd suggest you use EML directly.

That said, I'm actually having a hard time getting XML attributes to serialize correctly with emld which actually should work. I think we'd run:

library(EML)

me <- list(individualName = list(givenName = "Example", surName = "User"))
my_eml <- list(dataset = list(
  title = "A Minimal Valid EML Dataset",
  creator = me,
  contact = me)
)

my_eml$dataset$coverage$taxonomicCoverage <- list(
  taxonomicClassification = list(
    taxonRankName = "Species",
    taxonRankValue = "Gypsophila paniculata",
    taxonId = list(
      "#provider" = "ITIS", 
      value = "20293")
))

write_eml(my_eml, "ex.xml")

But I'm getting a taxonId element that looks like this:

<taxonId>
  <#provider>ITIS</#provider>
  <value>20293</value>

@cboettig any thoughts? I didn't see any unit tests or such that show this working though I do note that our eml-2.2.0.json does have what looks like the right data for taxonId: "taxonId": ["#provider"],.

@thesadie I'm not sure if we need to fix anything at this point but we'll update here as we discuss.