2014-10-29 23 views
1

我想基於具有特定孩子列表的節點創建新的scala.xml.Elem。 這將是遞歸替換函數中的返回情況。使用特定的孩子創建scala.xml.Elem

val childs: Seq[Node] = update(node.child) 
new Elem(node.prefix, node.label, node.attributes, node.scope, true, childs) 

這種結構會產生編譯錯誤:

Error:(50, 11) overloaded method constructor Elem with alternatives: 
    (prefix: String,label: String,attributes: scala.xml.MetaData,scope: scala.xml.NamespaceBinding,child: scala.xml.Node*)scala.xml.Elem <and> 
    (prefix: String,label: String,attributes1: scala.xml.MetaData,scope: scala.xml.NamespaceBinding,minimizeEmpty: Boolean,child: scala.xml.Node*)scala.xml.Elem 
    cannot be applied to (String, String, scala.xml.MetaData, scala.xml.NamespaceBinding, Boolean, Seq[scala.xml.Node]) 
     new Elem(node.prefix, node.label, node.attributes, node.scope, true, childs) 
    ^

到VARARG處理的問題是相關的,我不明白爲什麼我有這樣的錯誤。任何想法?

更新 我能夠通過問題下面醜陋結構得到:

val childs: Seq[Node] = update(node.child) 
Elem(node.prefix, node.label, node.attributes, node.scope, true) 
    .copy(node.prefix, node.label, node.attributes, node.scope, true, childs) 

首先創建一個沒有孩子的的ELEM,然後複製並添加孩子的。複製方法定義沒有可變參數。

回答

2

您的scopeminimizeEmpty參數按錯誤順序排列。

嘗試調用它像這樣(請注意我用的同伴對象也節省了幾個字符):

Elem(node.prefix, node.label, node.attributes, node.scope, true, childs) 

更新的問題進行了更新後 - 啊,現在我看到你的問題 - childsSeq[Node],但Elem構造函數方法期望Node*;所以你可以使用:

Elem(node.prefix, node.label, node.attributes, node.scope, true, childs:_*) 
+0

UUUps,從1000個試驗中發佈了錯誤的組合。不幸的是,正確的順序也不起作用。 我編輯原來的帖子來解決「打字錯誤」。 無論如何謝謝你的答案。 – ZsJoska 2014-10-30 07:57:06

+0

謝謝你的回答 – ZsJoska 2014-10-30 15:47:43

相關問題