class XMLReader extends Serializable
Class to parse and read XML files.
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- XMLReader
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- All
Instance Constructors
-
new
XMLReader(storeContent: Boolean = false, xmlKeepTags: Boolean = false, onlyLeafNodes: Boolean = true)
- storeContent
Whether to include the raw XML content in the resulting DataFrame as a separate 'content' column. By default, this is false.
- xmlKeepTags
Whether to retain original XML tag names and include them in the metadata for each extracted element. Useful for preserving structure. Default is false.
- onlyLeafNodes
If true, only the deepest elements (those without child elements) are extracted. If false, all elements are extracted. Default is true.
Input Format
Input must be a valid path to an XML file or a directory containing XML files.
Example
val xmlPath = "./data/sample.xml" val xmlReader = new XMLReader() val xmlDf = xmlReader.read(xmlPath)
xmlDf.show(truncate = false) +----------------------+--------------------------------------------------+ |path |xml | +----------------------+--------------------------------------------------+ |file:/data/sample.xml |[{Title, My Book, {tag -> title}}, ...] | +----------------------+--------------------------------------------------+ xmlDf.printSchema() root |-- path: string (nullable = true) |-- xml: array (nullable = true) | |-- element: struct (containsNull = true) | | |-- elementType: string (nullable = true) | | |-- content: string (nullable = true) | | |-- metadata: map (nullable = true) | | | |-- key: string | | | |-- value: string (valueContainsNull = true)
For more examples refer to: notebook
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hash(s: String): String
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def parseXml(xmlString: String): List[HTMLElement]
- def read(inputSource: String): DataFrame
- def setOutputColumn(value: String): XMLReader.this.type
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()