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

I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I'm trying to build an object that looks something like this: public class MyObject
I have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>
I have xml like this: <rule> <word>I</word> <word>need</word> <word>more</word> <marker> <word>money</word> </marker> <word>now</word> </rule>
I have a parent-/child relationship of folders, which looks like this: A folder can
I have an existing data model. I would like to express this data model
I have a Grails project that is using Hibernate XML. The Hibernate file are
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>

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.