Skip to content

Commit

Permalink
Add new 'declaration' option to control generation of an XML declarat…
Browse files Browse the repository at this point in the history
…ion, and default to generating a standard one.
  • Loading branch information
srowen committed Sep 29, 2021
1 parent e64814a commit b91ffc1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ When writing files the API accepts several options:
* `path`: Location to write files.
* `rowTag`: The row tag of your xml files to treat as a row. For example, in `<books> <book><book> ...</books>`, the appropriate value would be `book`. Default is `ROW`.
* `rootTag`: The root tag of your xml files to treat as the root. For example, in `<books> <book><book> ...</books>`, the appropriate value would be `books`. It can include basic attributes by specifying a value like `books foo="bar"` (as of 0.11.0). Default is `ROWS`.
* `declaration`: Content of XML declaration to write at the start of every output XML file, before the `rootTag`. For example, a value of `foo` causes `<?xml foo?>` to be written. Set to null or empty to suppress. Defaults to `version="1.0" encoding="UTF-8"`. New in 0.14.0.
* `declaration`: Content of XML declaration to write at the start of every output XML file, before the `rootTag`. For example, a value of `foo` causes `<?xml foo?>` to be written. Set to null or empty to suppress. Defaults to `version="1.0" encoding="UTF-8" standalone="yes"`. New in 0.14.0.
* `nullValue`: The value to write `null` value. Default is string `null`. When this is `null`, it does not write attributes and elements for fields.
* `attributePrefix`: The prefix for attributes so that we can differentiating attributes and elements. This will be the prefix for field names. Default is `_`.
* `valueTag`: The tag used for the value when there are attributes in the element having no child. Default is `_VALUE`.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/databricks/spark/xml/XmlOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private[xml] object XmlOptions {
val DEFAULT_VALUE_TAG = "_VALUE"
val DEFAULT_ROW_TAG = "ROW"
val DEFAULT_ROOT_TAG = "ROWS"
val DEFAULT_DECLARATION = "version=\"1.0\" encoding=\"UTF-8\""
val DEFAULT_DECLARATION = "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\""
val DEFAULT_CHARSET: String = StandardCharsets.UTF_8.name
val DEFAULT_NULL_VALUE: String = null
val DEFAULT_WILDCARD_COL_NAME = "xs_any"
Expand Down
3 changes: 2 additions & 1 deletion src/test/scala/com/databricks/spark/xml/XmlSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ final class XmlSuite extends AnyFunSuite with BeforeAndAfterAll {
.options(Map("rootTag" -> "books", "rowTag" -> "book"))
.xml(copyFilePath2.toString)

assert(getLines(copyFilePath2.resolve("part-00000")).head ==="<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
assert(getLines(copyFilePath2.resolve("part-00000")).head ===
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>")
}

test("DSL save with nullValue and treatEmptyValuesAsNulls") {
Expand Down

0 comments on commit b91ffc1

Please sign in to comment.