class XMLReader extends Serializable
Class to parse and read XML files.
Linear Supertypes
Ordering
- Alphabetic
- By Inheritance
Inherited
- XMLReader
- Serializable
- AnyRef
- Any
- Hide All
- Show All
Visibility
- Public
- Protected
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(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- def hash(s: String): String
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @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
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @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(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
(Since version 9)