0

I want to read XML file in Databricks using pyspark. The xml code is given below

<BepVehicleTestResult>
<VehicleBuild>
   <ABS>
      <MaximumSensorSpeed Descritpion="Maximum allowable sensor speed" Units="MPH">7.0</MaximumSensorSpeed>      
      <MinimumSensorSpeed Description="Minimum allowable sensor speed" Units="MPH">3.0</MinimumSensorSpeed>      
      <RearSensorLoaction Descritpion="Location of Rear ABS Sensor" ValidTypes="Front,Rear">Front</RearSensorLoaction>      
      <SensorTestSpeed Description="Roll speed for the sensor test" Units="MPH">5</SensorTestSpeed>     
      <SensorTestStartDelay Units="mSec">3000</SensorTestStartDelay>   
   </ABS> 
   <Axle>MainAxle</Axle>   
   <BrakeDistance>
      <FrontMaximumStoppingDistance Units="Feet">42.65</FrontMaximumStoppingDistance>     
      <FrontMinimumStoppingDistance Units="Feet">5.0</FrontMinimumStoppingDistance>      
      <RearMaximumStoppingDistance Units="Feet">42.65</RearMaximumStoppingDistance>     
      <RearMinimumStoppingDistance Units="Feet">5.0</RearMinimumStoppingDistance>   
   </BrakeDistance>  
  • Hi Sankar, seems you are the new user of SO. Please format the question accordingly, otherwise, it has a low chance to survive a moderation – Alexander Volok Oct 02 '22 at 17:28
  • Hi Alex. I have a xml file which is having multiple tags. So I would like to have pyspark code to read that. – Sankar Azad Oct 02 '22 at 17:29
  • But why you then cannot place it as the input? You can use wrap it with triple ticks, like ``` your data ``` to preserve formatting. I just did it for you ) – Alexander Volok Oct 02 '22 at 17:31
  • Perhaps, this sample notebook might be a solution for you: https://github.com/raveendratal/PysparkTelugu/blob/master/Read_Write_XML_File.ipynb – Alexander Volok Oct 02 '22 at 17:34
  • Your XML misses closing `` and `` – ZygD Oct 03 '22 at 07:43
  • @ZygD Could you please refer this link for the whole code. https://github.com/sankarkumarazad123/xml/blob/main/MAT476124K0H11297.xml – Sankar Azad Oct 03 '22 at 10:33
  • Please review the link above. It seems someone had asked the same question before. Which makes this question a duplicate, so it should be closed, as it already has an answer elsewhere, just just need to study it. – ZygD Oct 03 '22 at 10:59
  • @ZygD I saw the link above but is different. Could you at least once see my xml code. – Sankar Azad Oct 03 '22 at 11:15
  • @AlexanderVolok could you also please look at the xml code I provided in the link above. – Sankar Azad Oct 03 '22 at 11:18

0 Answers0