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

  • Home
  • SEARCH
  • 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 6159337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:06:56+00:00 2026-05-23T21:06:56+00:00

I’m relatively new to working with Scala having recently come from a java background.

  • 0

I’m relatively new to working with Scala having recently come from a java background.

I’m seeking advice on creating an efficient s means of reading an XML file and extracting element names and properties contained within where the data is enclosed between parentheses.

For example

< some name >{property}< some name/ >

So the key is where there is data contained within {}

I then want to populate a hash map with the actual element names and property values contained between {}.

I’m sure this is not overly complex but given my limited Scala expertise at this time I’d like to bounce this question off the expertise within the forum.

Many thanks to anyone taking time to answer.

  • 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-05-23T21:06:56+00:00Added an answer on May 23, 2026 at 9:06 pm

    [UPDATED]
    Just realized that you’ve asked about braces in text, not about xml-related syntax braces.
    The possible answer is:

    scala> val xml = <a>
                       <prop>{{key1}}</prop>
                       <prop>{{key2}}</prop>
                       <prop>notkey</prop>
                     </a>
    xml: scala.xml.Elem = <a><prop>{key1}</prop><prop>{key2}</prop><prop>notkey</prop></a>
    

    I’ve doubled { and } to escape braces, because Scala treat {variable} as a substitute:

    scala> val text="all your base are belong to us"
    text: java.lang.String = all your base are belong to us
    
    scala> val template = <a>{text}</a>
    template: scala.xml.Elem = <a>all your base are belong to us</a>
    

    Now back to work.
    To take only prop's use \ projection operator, which takes subnodes with a given name. To take all sub-sub-…-sub nodes in xml tree use instead \\.

    scala> val props = xml\"prop"
    props: scala.xml.NodeSeq = NodeSeq(<prop>{key1}</prop>, <prop>{key2}</prop>, <prop>notkey</prop>)
    
    val keys = props.filter (p => p.text.startsWith("{"))
    res3: scala.xml.NodeSeq = NodeSeq(<prop>{key1}</prop>, <prop>{key2}</prop>)
    

    Actually, i’m cheated here, and supposed that non-desired property field cannot exist in form {notkey. You can rewrite code to filter keys in another manner (e.g. using regexp’s)

    scala> for(k <- keys) {
         | println(k.label+":"+k.text)
         | }
    prop:{key1}
    prop:{key2}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to Oracle, having working on MS SQL for most of my
I am relatively new to asp.net environment. Recently working on a project, i discovered
I'm relatively new to Python and am having problems programming with Scapy, the Python
I'm relatively new to working with XML and am working with some rather large
I'm relatively new to working with the UI in Seam, so I'm hoping there
I'm working on a relatively new project using Subversion. I've already branched off a
I'm relatively new to .NET GUI programming using WinForms (the project I'm working on
I'm relatively new to version control, and so far only have experience working with
I am working on a Google App Engine application and I am relatively new
I’m an experienced developer, but relatively new to iOS. I’m having some trouble with

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.