【发布时间】:2017-04-03 18:39:48
【问题描述】:
我需要解析一个 XML 节点,它的文本中可能包含也可能不包含其他 XML:
输入
<! -- i. no xml nested within text -->
<my.element>
This is some text. It's simple and easy.
</my.element>
<! -- ii. no xml nested within text -->
<my.element>
This is some text. It comes with <other.xml ID="1234" type="x" ...>1</other.xml> xml element nested within it's text.
</my.element>
输出
# i.
"This is some text. It's simple and easy."
# ii.
"This is some text. It comes with [1] other xml element nested within its text."
问题是如何可靠地将my.element 文本与嵌套元素other.xml 的文本分开。
每个元素都作为scala.xml.NodeSeq 加载,就好像内部xml 或多或少被忽略(即无法通过label 对其应用逻辑)。我能做的最好的就是得到text。复制内部元素的text:
foo.text
String =
"This is some text. It comes with
1
1
other xml element nested within its text."
这是一个简单的例子。实际上,我正在处理 TB 或更多的数据,并且需要处理大量可变数量的潜在嵌套 xml 元素。有些像上面那样提取和合并文本,有些可以忽略,有些格式不同等等。
这与 Spark 有关,因为我需要解决方案可序列化并使用 Spark 大规模运行。
【问题讨论】:
-
apache-spark标签与这个问题有什么关系? -
@TzachZohar 我需要可序列化的解决方案,以便我可以使用 Spark 大规模运行它。
标签: xml scala apache-spark