我正在从外部数据存储解析一系列XML响应.在此期间,我必须测试是否存在子节点,并且 - 如果存在 - 测试其值.为此,我有以下代码:
...
val properties = for {
val row <- root \\ "ResultDescription"
val cond:Boolean = checkDetectionNode(row) match {
case Some(nodeseq) => {
val txt = nodeseq.text.toLowerCase
if (txt contains "non-detect")
false
else
true
}
case None => true
}
if (cond)
val name = (row \ "CharacteristicName").text
if (charNameList.exists(s => s == name) == false)
} yield {
getObservedProperty(name) match {
case Some(property) => {
charNameList = name :: charNameList
property
}
}
}
... …Run Code Online (Sandbox Code Playgroud)