I have a spark dataframe, which has a columns value
, key
and others, value
column has an xml as string
Now i would like to create a new dataframe where the xml content of value
column is read as if i am reading spark.read.xml
and append the other columns like key
to the new DF
Is this possible?
I am generally reading the xml files using this
dfx = spark.read.load('books.xml', format='xml', rowTag='bks:books', valueTag="_ele_value")
dfx.schema
Trying to get the similar dataframe output when trying to read it from the value
column (this is coming from kafka)
My xml has a deeply nested structure, just a example of books xml with 2 levels nested
<?xml version="1.0" encoding="UTF-8"?>
<bks:books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bks="urn:books"
xsi:schemaLocation="urn:books books.xsd" xmlns:ot="http://maven.apache.org/POM/4.0.0">
<book id="b001">
<author>Brandon Sanderson</author>
<title>Mistborn</title>
<genre sub='epic'>Fantasy</genre>
<price>50</price>
<pub_date>2006-12-17T09:30:47.0Z</pub_date>
<review>
<title>Wonderful</title>
<content>I love the plot twist and the new magic</content>
</review>
<review>
<title>Unbelievable twist</title>
<content>The best book i ever read</content>
</review>
<sold>10</sold>
</book>
<book id="b002">
<author>Brandon Sanderson</author>
<title>Way of Kings</title>
<genre sub='epic'>Fantasy</genre>
<price>50</price>
<pub_date>2006-12-17T09:30:47.0Z</pub_date>
<sold>10</sold>
</book>
</bks:books>