change read_xml to read_html + 2 xml_child
diff --git a/NAMESPACE b/NAMESPACE
index a8af5b9..dfc6fb1 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -35,6 +35,7 @@
 importFrom(xml2,"xml_text<-")
 importFrom(xml2,read_html)
 importFrom(xml2,read_xml)
+importFrom(xml2,write_xml)
 importFrom(xml2,xml_add_child)
 importFrom(xml2,xml_add_sibling)
 importFrom(xml2,xml_attr)
diff --git a/R/kableExtra-package.R b/R/kableExtra-package.R
index a690e84..4b89362 100644
--- a/R/kableExtra-package.R
+++ b/R/kableExtra-package.R
@@ -55,7 +55,7 @@
 #' str_extract str_replace_all str_trim str_extract_all str_sub
 #' @importFrom xml2 read_xml xml_attr xml_has_attr xml_attr<- read_html
 #' xml_child xml_children xml_name xml_add_sibling xml_add_child xml_text
-#' xml_remove xml_text<-
+#' xml_remove write_xml xml_text<-
 #' @importFrom rvest html_table
 #' @importFrom knitr knit_meta_add
 #' @importFrom rmarkdown latex_dependency
diff --git a/R/kable_styling.R b/R/kable_styling.R
index fbd26f9..bf2da86 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -101,7 +101,7 @@
                                            "float_left", "float_right"),
                               font_size = NULL) {
   kable_attrs <- attributes(kable_input)
-  kable_xml <- read_xml(as.character(kable_input), options = c("COMPACT"))
+  kable_xml <- read_kable_as_xml(kable_input)
 
   # Modify class
   bootstrap_options <- match.arg(
diff --git a/R/util.R b/R/util.R
index 9d4146e..40dab5e 100644
--- a/R/util.R
+++ b/R/util.R
@@ -74,8 +74,13 @@
 as_kable_xml <- function(x) {
   tmp <- tempfile(fileext = ".xml")
   write_xml(x, tmp, options = "no_declaration")
-  out <- readLines(tmp)
-  out <- paste(out, collapse = "\n ")
+  out <- readLines(tmp, warn = FALSE)
+  out <- paste(out, collapse = "\n")
   out <- structure(out, format = "html", class = "knitr_kable")
   return(out)
 }
+
+read_kable_as_xml <- function(x) {
+  kable_html <- read_html(as.character(x))
+  xml_child(xml_child(kable_html, 1), 1)
+}