2011-03-09 61 views
2

什麼是採取與任意文本格式的文檔的最好辦法,說:功能XML建設階

Hello world 

1.1.1 (John Doe) 

Paragraph one here... pargraph one continued here 

paragraph two here 

並將其轉換成一個看起來像這樣的XML文檔:

<note id="1.1.1" author_first = "John" author_last = "Doe"> 
    <paragraph>Paragraph one here... paragraph one continued here</paragraph> 
    <paragraph>paragraph two here</paragraph> 
</note> 

我能想到的唯一方法是使用XMLBuilder類型類的標準命令方式是說Scanner。但是,這看起來不像習慣斯卡拉。

謝謝!

回答

1

假設你已經分析的數據,你可以只是去用文字的方式...

val paragraphs: List[String] = ... 
val noteId: String = ... 
val authorName: (String, String) = ... 

<note id={noteId} author_first={authorName._1} author_last={authorName._2}> 
    {paragraphs.map(s => <paragraph>{s}</paragraph>)} 
</note> 
+0

請注意,如果您還沒有分析的數據,有多種方法可以做到其中沒有涉及XML。 :) – 2011-03-15 17:25:51