Support Questions
Find answers, ask questions, and share your expertise

spark scala: if i have an empty XML tag , returning null while parsing XML using com.databricks.spark.xml

spark scala: if i have an empty XML tag , returning null while parsing XML using com.databricks.spark.xml

I am getting null values when i have an empty XML tag .

<TransactionMessage>

<TransactionGuid> </TransactionGuid>

<MessageMsmqId><MessageMsmqId>

<TransactionXmlMessage>

<Transaction>

<Items></Items>

<Discounts />

</Transaction>

</TransactionXmlMessage>

</TransactionMessage>

Since Discount is empty , the whole XML parser is null as below :

MachineName| MessageMsmqId| TransactionGuid|TransactionXmlMessage| +-----------+--------------------+--------------------+---------------------+ | null| null| null| null|

val pomXML = spark.<br>  sqlContext.<br>  read.<br>  format("com.databricks.spark.xml").<br>  option("rootTag", "TransactionMessage").<br>  load(s"pathpofthye file")