2012-09-13 31 views
1

我想根据SdkMessageProcessingStepImageId的值选择SdkMessageProcessingStepId属性,请参阅下面的xml,但我很挣扎。linq to xml根据子值选择父属性

<SdkMessageProcessingStep Name="Plugins.OnPreCreateUpdateCar: Update of new_car" SdkMessageProcessingStepId="{00c19595-76fd-e111-9528-005056af005a}"> 
    <PluginTypeName>Plugins.OnPreCreateUpdateCar, Plugins, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f59c17e3653dba0</PluginTypeName> 
    <PrimaryEntity>new_car</PrimaryEntity> 
    <AsyncAutoDelete>0</AsyncAutoDelete> 
    <InvocationSource>1</InvocationSource> 
    <Mode>0</Mode> 
    <Rank>1</Rank> 
    <SdkMessageId>{20bebb1b-ea3e-db11-86a7-000a3a5473e8}</SdkMessageId> 
    <EventHandlerTypeCode>4602</EventHandlerTypeCode> 
    <Stage>20</Stage> 
    <IsCustomizable>1</IsCustomizable> 
    <IsHidden>0</IsHidden> 
    <SupportedDeployment>0</SupportedDeployment> 
    <SdkMessageProcessingStepImages> 
    <SdkMessageProcessingStepImage Name="PreImageCar"> 
     <SdkMessageProcessingStepImageId>{e3c5bcb1-76fd-e111-9528-005056af005a}</SdkMessageProcessingStepImageId> 
     <EntityAlias>PreImageCar</EntityAlias> 
     <ImageType>0</ImageType> 
     <MessagePropertyName>Target</MessagePropertyName> 
     <IsCustomizable>1</IsCustomizable> 
    </SdkMessageProcessingStepImage> 
    </SdkMessageProcessingStepImages> 
</SdkMessageProcessingStep> 

我尝试了各种各样的东西,例如两个查询,连接,但似乎没有任何工作。最后,我选择了一个完全不同的解决方案,但知道如何在一个查询中执行此操作会很方便。

TIA

+0

你能给比如你查询的,它有助于我们理解你的问题更好 – testCoder

回答

1

我不确定你想要达到的目标。但也许这将帮助:

XElement xmlTree = XElement.Load(source); 

string[] result = xmlTree.Descendants("SdkMessageProcessingStepImageId") 
       .Where(element => element.Value == "{e3c5bcb1-76fd-e111-9528-005056af005a}") 
       .Select(element => element.Parent.Parent.Parent) 
       .Attributes() 
       .Where(attribute => attribute.Name == "SdkMessageProcessingStepId") 
       .Select(attribute => attribute.Value) 
       .ToArray(); 

结果:

{00c19595-76fd-e111-9528-005056af005a} 
+0

感谢该做的伎俩。下次必须记得使用Parent。 – ManyRootsofAllEvil