diff --git a/src/test/resources/self-closing-tag.xml b/src/test/resources/self-closing-tag.xml new file mode 100644 index 00000000..c3057b22 --- /dev/null +++ b/src/test/resources/self-closing-tag.xml @@ -0,0 +1,6 @@ + + + 1 + + + diff --git a/src/test/scala/com/databricks/spark/xml/XmlSuite.scala b/src/test/scala/com/databricks/spark/xml/XmlSuite.scala index 281a7447..e1bc484e 100755 --- a/src/test/scala/com/databricks/spark/xml/XmlSuite.scala +++ b/src/test/scala/com/databricks/spark/xml/XmlSuite.scala @@ -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" @@ -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)) + } }