I am reading a csv file from ADLSGEN2 using databricks read API.
The csv file contains only one column which contains Power Shell(clixml) content.
While trying to extract with spark-xml functions ,I am not getting the correct schema and records are corrupted.
So please help me to convert the clixml to xml or exact solution to extract the xml content.
Code Block:
import com.databricks.spark.xml._
import com.databricks.spark.xml.from_xml_string
import com.databricks.spark.xml.functions.from_xml
import org.apache.spark.sql.functions.{col}
import org.apache.spark.sql.types.{StructType}
import spark.implicits._
var path = "csvpath"
val df= spark.read
.option("header","false")
.option("inferschema","true")
.csv(path)
val dfrename= df.withColumnRenamed("_c0","xmldata")
val xmlSchema = schema_of_xml(dfrename.select("xmldata").as[String])
val xmlDF = dfrename.withColumn("xmldata", from_xml(col("xmldata"), xmlSchema))
display(xmlDF )
XML Content: Sample
<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04">
<Obj RefId="0">
<DT>2018-03-21T08:05:39.5085956-04:00</DT>
<MS>
<Obj N="DisplayHint" RefId="1">
<TN RefId="0">
<T>Microsoft.PowerShell.Commands.DisplayHintType</T>
<T>System.Enum</T>
<T>System.ValueType</T>
<T>System.Object</T>
</TN>
<ToString>DateTime</ToString>
<I32>2</I32>
</Obj>
</MS>
</Obj>
</Objs>