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