Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8544681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:37:09+00:00 2026-06-11T12:37:09+00:00

I am parsing a series of XML responses from a external data store. During

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:37:10+00:00Added an answer on June 11, 2026 at 12:37 pm

    The xml is a distraction here. The problem is the if (cond) at the end is not acting as a guard, it just looks like it should, the compiler thinks is the start of a new if ‘then’ part.

    In the following example:

    val l = List(1,2,3,4,5)
    
    val r = for {
        i <- l 
          if (i > 2)
        x <- Some(i * 2)
      } yield x
    

    you’ll get List(6,8,10) as you might expect.

    Using

    val r = for {
        val i <- l if (i > 2)
        val x <- Some(i * 2)
      } yield x
    

    should get you a deprecation warning, and

    val r = for {
        val i <- l 
        if (i > 2)
        val x <- Some(i * 2)
      } yield x
    

    gets

    error: illegal start of simple expression
      val x <- Some(i * 2)
    

    Simply remove the val in front of your Generator (Pattern1 ‘<-’ Expr [Guard]), and you can resume normal service. It also flows a bit more nicely without the vals in the for loop I find.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem parsing a XML file which contains special characters like ,
I'm trying to get data from a webpage that serves a XML file periodically
I'm using CasperJS to automate a series of clicks, completed forms, parsing data, etc
When parsing an xml file in android, I'm doing like this: try { InputStream
Not parsing the parameters in the beginning but parse the input string read from
I'm parsing a date from a JSON event feed - but the date shows
I wrote a script parsing a .csv file in groovy using tokenize, which ended
As I understood it before taking this job, XML Uses a series of key-value
I am using SAX to parse an XML file I'm pulling from the web.
Hello I have an api response in xml format with a series of items

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.