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 6798835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:46:39+00:00 2026-05-26T18:46:39+00:00

Remark: please consider XPath syntax dead here, thank you. I have xml node (HTML

  • 0

Remark: please consider XPath syntax dead here, thank you.

I have xml node (HTML actually), and I would like to get an attribute of it.

In C# (HTMLAgilityPack) I could get attribute object by name. For example having "a" node I could ask for "href" attribute.

In Scala there is "attribute" method within xml.Node, but this returns a sequence of.. nodes. An attribute is a node? How it is possible to have several attributes with the same name? I am completely puzzled.

Moreover there is xml.Attribute class but I don’t see it used in xml.Node.

I have PiS book but XML chapter is very shallow.

The question

How should I understand asking for an attribute an getting collection of nodes?

IOW: what sense is in returning an option of collection of nodes instead of returning attribute?

  • option — if there is no attribute, collection should be empty, it is doubling semantics
  • collection — this implies there are multiple attribute possible, so I am curious in what scenario I get collection of size > 1
  • node — attribute is pretty simply entity, why such overkill and suggesting that attribute can have tree structure
  • 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-26T18:46:40+00:00Added an answer on May 26, 2026 at 6:46 pm

    You just want to get the value of an attribute, yes? In which case that’s pretty easy:

    scala> val x = <foo this="xx" that="yy" />
    x: scala.xml.Elem = <foo this="xx" that="yy"></foo>
    
    scala> x.attribute("this")
    res0: Option[Seq[scala.xml.Node]] = Some(xx)
    
    scala> x.attribute("this").get.toString
    res1: String = xx
    

    I know that you said that you explicitly aren’t interested in XPath syntax, but in this instance it really is rather neater:

    scala> x \ "@this"
    res2: scala.xml.NodeSeq = xx
    

    Having said all of this, you should be aware that there are many problems with attribute handling in Scala’s built-in XML handling. See, for example, this, this and this.

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

Sidebar

Related Questions

First of all I would like to remark I am new with the concept
I have an xml with no data (for example the data for remark tag),
Following the discussions here on SO I already read several times the remark that
See here: http://code.google.com/p/ie7-js/ Does anyone have any experience or remarks about this javascript? Is
Updates : Please see below i have table: data +-----------------------+--------------+-----------+ | State | d_country
I have splitted comma separated values in an string array, something like this str[0]
This topic is a remark for PHP get image src So we have a
So I'm probably missing the obvious here, but what actually is the difference between
I am making a quiz app and want it to have a 'witty remark'
i have tried to prevent the duplicate data at my project. but until now

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.