小编Cow*_*wan的帖子

Scala XML:测试节点的存在和价值

我正在从外部数据存储解析一系列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)

xml scala

5
推荐指数
1
解决办法
3944
查看次数

标签 统计

scala ×1

xml ×1