I am parsing a series of XML responses from a external data store. During which I must test for the existence of a child node and - if it exists - test its value. To achieve that I have the following code:
...
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
}
}
}
...
checkDetectionNode is defined as such:
private def checkDetectionNode(row: scala.xml.NodeSeq) : Option[scala.xml.NodeSeq] = {
if ((row \ "ResultDetectionConditionText") != null)
Some[scala.xml.NodeSeq]((row \ "ResultDetectionConditionText"))
else
None
}
The above code results in an unspecified error of "illegal start of simple expression" on the val name... line. To be honest I am not a Scala programmer or even a functional programmer (always was more partial to OO/imperative). I've only been using Scala for a few days and been basing most of what I know from Java and lambda operators. Unfortunately, I don't really have the time to sit down and really learn Scala like I wish I could. Deadlines, make fools of us all.
I am hoping that someone could take a look and let me know if there is something I am doing wrong (as I am sure there is). I tried to limit the code shown to, what I hope, is relevant to the question. However, please let me know if any additional code is needed.
Thanks
if(cond)is suppose to be for determining the execution of the yield block. I've edited my answer to elaborate more on the code.