xiaonanyang-db commented on code in PR #50300:
URL: https://github.com/apache/spark/pull/50300#discussion_r2035847582


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/xml/StaxXmlParser.scala:
##########
@@ -897,4 +914,219 @@ object StaxXmlParser {
       curRecord
     }
   }
+
+  /**
+   * Parse the input XML string as a Variant value
+   */
+  def parseVariant(xml: String, options: XmlOptions): VariantVal = {
+    val parser = StaxXmlParserUtils.filteredReader(xml)
+    val rootEvent =
+      StaxXmlParserUtils.skipUntil(parser, XMLStreamConstants.START_ELEMENT)
+    val rootAttributes = rootEvent.asStartElement.getAttributes.asScala.toArray
+    val variant = convertVariant(parser, rootAttributes, options)
+    val v = new VariantVal(variant.getValue, variant.getMetadata)
+    parser.close()
+    v
+  }
+
+  /**
+   * Parse an XML element from the XML event stream into a Variant.
+   * This method transforms the XML element along with its attributes and 
child elements
+   * into a hierarchical Variant data structure that preserves the XML 
structure.
+   *
+   * @param parser The XML event stream reader positioned after the start 
element
+   * @param attributes The attributes of the current XML element to be 
included in the Variant
+   * @param options Configuration options that control how XML is parsed into 
Variants
+   * @return A Variant representing the XML element with its attributes and 
child content
+   */
+  def convertVariant(

Review Comment:
   We don't have the validation in `convertObject` in spark, do you think we 
should add that to both path?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to