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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:09:55+00:00 2026-05-16T11:09:55+00:00

I have an XML string that looks like this: <Attributes> <ProductAttribute id=1> <ProductAttributeValue> <Value>a</Value>

  • 0

I have an XML string that looks like this:

<Attributes>
    <ProductAttribute id="1">
        <ProductAttributeValue>
            <Value>a</Value>
        </ProductAttributeValue>
    </ProductAttribute>
    <ProductAttribute id="2">
        <ProductAttributeValue>
            <Value>a</Value>
        </ProductAttributeValue>
        <ProductAttributeValue>
            <Value>b</Value>
        </ProductAttributeValue>
    </ProductAttribute>    
</Attributes>

I would like to return an IEnumerable like this:

Id Value
1  a
2  a b

I have tried this and only got the “b” value for Id “2”:

XElement e = XElement.Parse(xmlString);
var q = from pa in e.Elements("ProductAttribute")
from pav in pa.Elements("ProductAttributeValue").Elements("Value")
select new
{
Id = (int)pa.Attribute("id"),
Value = (string)pav
};

I tried this:

 XElement e = XElement.Parse(xmlString);
    var q = from pa in e.Elements("ProductAttribute")
    select new
    {
    Id = (int)pa.Attribute("id"),
    Value = pa.Elements("ProductAttributeValue").Elements("Value")
    };

But could not cast Value as a string. Using LINQPad the output was like this:

Id Value
1  a
2  <Value>a</Value>
   <Value>b</Value>

I am trying to just return the values. Is this even possible?

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-05-16T11:09:55+00:00Added an answer on May 16, 2026 at 11:09 am

    If you wanted a contatenated string of those values like "a b"

     XElement e = XElement.Parse(xmlString);
        var q = from pa in e.Elements("ProductAttribute")
        select new
        {
        Id = (int)pa.Attribute("id"),
         Value = string.Join(" " ,
                        pa.Elements("ProductAttributeValue")
                         .Elements("Value")                                            
                         .Select(x=>x.Value)
                         .ToArray())
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string of XML that looks like this: <e1 atr1=3 atr2=asdf> <e1b
So i have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <gesmes:Envelope
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
I have a XML Structure that looks like this. <sales> <item name=Games sku=MIC28306200 iCat=28
I have an xml file that looks something like this <questions> <question> <text>What color
I have a xml that looks like this, <Parent> Running text with marked up
I have an xml that looks like this: <Root> <tag1>4</tag1> <tag2>aa</tag2> <tag3 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema>
I have an XML/Soap file that looks like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope
I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20
I have some XML that looks like this: <abc x={></abc> I want to force

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.