Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/test/resources/self-closing-tag.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ROWSET>
<ROW>
<non-empty-tag>1</non-empty-tag>
<self-closing-tag/>
</ROW>
</ROWSET>
15 changes: 15 additions & 0 deletions src/test/scala/com/databricks/spark/xml/XmlSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class XmlSuite extends FunSuite with BeforeAndAfterAll {
val nestedElementWithNameOfParent = "src/test/resources/nested-element-with-name-of-parent.xml"
val booksMalformedAttributes = "src/test/resources/books-malformed-attributes.xml"
val fiasHouse = "src/test/resources/fias_house.xml"
val selfClosingTag = "src/test/resources/self-closing-tag.xml"

val booksTag = "book"
val booksRootTag = "books"
Expand Down Expand Up @@ -917,4 +918,18 @@ class XmlSuite extends FunSuite with BeforeAndAfterAll {
assert(df.collect().length == numFiasHouses)
assert(df.select().where("_HOUSEID is null").count() == 0)
}

test("Produces correct result for a row with a self closing tag inside") {
val schema = StructType(Seq(
StructField("non-empty-tag", IntegerType, nullable = true),
StructField("self-closing-tag", IntegerType, nullable = true)
))

val result = new XmlReader()
.withSchema(schema)
.xmlFile(sqlContext, selfClosingTag)
.collect()

assert(result(0).toSeq === Seq(1, null))
}
}