在XML中实现白名单

时间:2019-07-02 14:36:16

标签: xml scala

val xml = 
 <foo>
  <bar>hi world</bar>
  <bippy>how's it going </bippy>
   <inner>
     <start>it's 10 am</start>
     <hi>
       <there/>
     </hi>
   </inner>
 </foo>


val whitelist: Set[String] = Set("bar", "start")

def desiredFunction(whitelist: Set[String], xml: Elem): Elem = ???

desiredFunction(whitelist, xml) would evaluate to

<foo>
 <bar>hi world</bar>
 <bippy>NOT IN WHITELIST</bippy>
  <inner>
    <start>it's 10 am</start>
     <hi>
       <there/>
     </hi>
  </inner>
</foo>

scala-xml中是否已经存在这样的泛型函数?也许我可以递归地进行模式匹配?请指教。我不想使用专门针对此用例的代码。

0 个答案:

没有答案