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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:40:07+00:00 2026-05-15T21:40:07+00:00

I have an xml mapping file that looks something like this <colourMappings> <model name=modelX>

  • 0

I have an xml mapping file that looks something like this

<colourMappings>
    <model name="modelX">
        <mapping colour="White" configCode="1"></mapping>
        <mapping colour="Aluminium" configCode="2"></mapping>
        <mapping colour="Black" configCode="3"></mapping>
        <mapping colour="Blue" configCode="4"></mapping>
        <mapping colour="White Pearl" configCode="5"></mapping>
        <mapping colour="Graphite" configCode="6"></mapping>
        <mapping colour="Gunmetal" configCode="7"></mapping>
        <mapping colour="Indigo" configCode="8"></mapping>
        <mapping colour="Red" configCode="9"></mapping>
    </model>
    <model name="modelY">
        <mapping colour="White" configCode="1" stConfigCode= "xx" dgConfigCode="hj"></mapping>
        <mapping colour="Aluminium" configCode="2" stConfigCode= "xy" dgConfigCode="gh"></mapping>
        <mapping colour="Black" configCode="3" stConfigCode= "xt" dgConfigCode="fg"></mapping>
        <mapping colour="Blue" configCode="4" stConfigCode= "sd" dgConfigCode="fg"></mapping>
        <mapping colour="White Pearl" configCode="5" stConfigCode= "df" dgConfigCode="df"></mapping>
        <mapping colour="Graphite" configCode="6" stConfigCode= "xc" dgConfigCode="df"></mapping>
        <mapping colour="Gunmetal" configCode="7"  stConfigCode= "cv" dgConfigCode="cv"></mapping>
        <mapping colour="Indigo" configCode="8"  stConfigCode= "zx" dgConfigCode="vb"></mapping>
        <mapping colour="Red" configCode="9"  stConfigCode= "fg" dgConfigCode="cv"></mapping>
    </model>
</colourMappings>

I want to be able to pull out all the attributes and their values given a model name and colour

e.g.

given ModelY and White, I’d like to get configCode=”1″ stConfigCode= “xx” dgConfigCode=”hj”
This could be in any structure – array, list, whatever

I have been using Linq to XML but can’t get the correct syntax

XDocument mappings = XDocument.Load(@"D:\colour_mappings.xml");
var q = from c in mappings.Descendants("model")
                    where (string)c.Attribute("name") == "modelY" && (string)c.Descendants("mapping").Attributes("colour").FirstOrDefault() == "White"
                    select c.Attributes();

anyone know how to do this?

Happy to use any method, doesn’t necessarily need to be Linq

  • 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-15T21:40:08+00:00Added an answer on May 15, 2026 at 9:40 pm

    Update

    Summarized in a method:

    public IEnumerable<XAttribute> GetAttributes(string modelName, string colour)
    {
        XDocument mappings = XDocument.Load(@"D:\colour_mappings.xml");
    
        var q1 =
            from elm in mappings.Descendants("model")
            where (string)elm.Attribute("name") == "modelY"
            select elm;
    
        var q2 =
            from elm in q1.Descendants("mapping")
            where (string)elm.Attribute("colour") == "White"
            select elm.Attributes().Where(a => a.Name != "colour");
    
    
        foreach (IEnumerable<XAttribute> attributeList in q2)
        {
            foreach (XAttribute attribute in attributeList)
            {
                yield return attribute;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I'm trying to build an object that looks something like this: public class MyObject
I have XML with a value like the following: <products> <product id=1 name=All Products>
I have the following mapping file: <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping xmlns=urn:nhibernate-mapping-2.2 assembly=Project1.Accounts namespace=Project1.Core.Domain>
I have XML files in a directory that I wish to get over to
Greetings! If I have XML such as this: <Root> <AlphaSection> . . . </AlphaSection>
My question is the following. I have xml that is versioned by a namespace.
I have an XML that I want to load to objects, manipulate those objects
I have a large xml file (1Gb). I need to make many queries on
I have an XML file with the following format: <?xml version=1.0 encoding=UTF-8?> <Items> <Item

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.