2017-09-26 84 views
1

我是Apache Spark新手,我希望能够读取XML文件并计算每个标题的字数。 XML文件是这样的:在Apache Spark中更改分隔符

<title>first title</title> 
<words>there are seven words in this example</words> 
<title>second title</title> 
<words>there are more words here, ten words to be precise</words> 

我使用Python编写的Spark工作,但是当我输入

sc.textFile("file://...") 

它会自动拆分使用换行符(\ n)的为我的文件其分隔符。我希望它分成几行,直到它再次找到“< title>”。

我想获得会是这样的结果:

first title: 7 
second title: 10 

我怎样才能做到这一点?

在此先感谢

+0

你能检查这个https://stackoverflow.com/questions/46408558/how-to-handle-multi-line-rows-in-spark/46410029#46410029 –

回答

0

我建议给一个尝试spark-xml,如果你使用XML文件的工作。