Skip to content

<![CDATA[ not always recognized #342

@peterdesmet

Description

@peterdesmet

write_eml() will preserve text wrapped in <![CDATA[ and ]]> (expected), but the behaviour is not consistent:

library(EML)

text_1 <- "My text is <a href=\"https://example.com\">html</a>." # Does not work
text_2 <- "<em></em>My text is <a href=\"https://example.com\">html</a>." # Works
text_3 <- "My text is <em>html</em>." # Works

eml <- list(
  dataset = list(
    abstract = list(
      para = list(
        paste0("<![CDATA[", text_1, "]]>"),
        paste0("<![CDATA[", text_2, "]]>"),
        paste0("<![CDATA[", text_3, "]]>")
      )
    )
  )
)

EML::write_eml(eml, "test.xml")

Resulting XML:

<?xml version="1.0" encoding="UTF-8"?>
<eml:eml 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" packageId="ed7f9836-d2ae-4a04-9473-d377db387c54" system="uuid" xsi:schemaLocation="https://eml.ecoinformatics.org/eml-2.2.0 https://eml.ecoinformatics.org/eml-2.2.0/eml.xsd">
  <dataset>
    <abstract>
      <para>&lt;![CDATA[My text is &lt;a href="https://example.com"&gt;html&lt;/a&gt;.]]&gt;</para>
      <para><![CDATA[<em></em>My text is <a href="https://example.com">html</a>.]]></para>
      <para><![CDATA[My text is <em>html</em>.]]></para>
    </abstract>
  </dataset>
</eml:eml>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions