Skip to content
Snippets Groups Projects
Commit 6b46b8a0 authored by Johannes Boog's avatar Johannes Boog
Browse files

Merge branch '55-bugfix-warning_empty_xml_tag' into 'master'

Resolve "Throw Warning when finding an empty XML tag"

Closes #55

See merge request !43
parents 5a1334d5 79a9b86d
No related branches found
No related tags found
1 merge request!43Resolve "Throw Warning when finding an empty XML tag"
......@@ -170,24 +170,34 @@ node_to_object <- function(xml_node,
node_name <- xml2::xml_name(xml_node)
# joboog: I think this if statements should be combined to if-else
# statements to be more explicit and to catch errors easier.
#Node is leaf
if(length(xml2::xml_children(xml_node)) == 0){
xml_attrs <- xml2::xml_attrs(xml_node)
xml_text <- xml2::xml_text(xml_node)
xml_text_clean <-
stringr::str_remove_all(xml2::xml_text(xml_node),
"[\n|[:space:]]")
stringr::str_remove_all(xml_text, "[\n|[:space:]]")
if(xml_text_clean != "" &&
length(xml2::xml_attrs(xml_node)) != 0){
return(invisible(c(xml2::xml_attrs(xml_node),
xml_text = xml2::xml_text(xml_node))))
if(xml_text_clean != "" && length(xml_attrs) != 0){
return(invisible(c(xml_attrs, xml_text = xml_text)))
}
if(xml_text_clean != ""){
return(invisible(xml2::xml_text(xml_node)))
else if(xml_text_clean != ""){
return(invisible(xml_text))
}
else if(length(xml_attrs) != 0){
return(invisible(xml_attrs))
}
else if(xml_text_clean == "" && length(xml_attrs) == 0){
warning(paste(c("Tag '", xpath, "' was found empty.")))
return(NULL)
}
else{
stop(paste0("Unusual case for importing tag: '", xpath, "'."),
call. = F)
}
return(invisible(xml2::xml_attrs(xml_node)))
}
#Node is represented by subclass
......
......@@ -7,7 +7,6 @@
</processes>
<media>
<medium id="0">
<phases/>
<properties>
<property>
<name>diffusion</name>
......
......@@ -5,7 +5,7 @@
<python_script>bcs_laplace_eq.py</python_script>
<media>
<medium id="0">
<phases/>
<!--phases/-->
<properties>
<property>
<name>diffusion</name>
......
......@@ -45,6 +45,12 @@ test_that("node_to_object works for simple lists", {
expect_equal(my_list, list(b = "1", b = "2"))
})
test_that("node_to_object prints warning for empty tags", {
test_node <- xml2::read_xml("<test> </test>")
expect_warning(node_to_object(test_node, xpath = "/test"))
})
test_that("order_parameters works for classes with Ellipsis argument", {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment