Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guy please i Need your help. i have some XML File like this one at the bigining
XML
<?xml version="1.0" encoding="utf-8" ?>
<Orders>
  <Order OrderID ="104710"  Priority="normal">
    <Informations>
      <Infos InfosID="1047101"  MatName="mat1"  Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1047102" MatName="mat2" Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1047103" MatName="mat3" Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1047104" MatName="mat4" Status="Busy">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1047105" MatName="mat4" Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1047106" MatName="EX-11445GF" QTY="40" Status="Busy">
        <exam>
        </exam>
      </Infos>
    </Informations>
  </Order>
  <Order OrderID ="123788"  Priority="normal">
    <Informations>
      <Infos InfosID="1237881"  MatName="mat1"  Status="Busy">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1237882" MatName="mat2" Status="Busy">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1237883" MatName="mat3" Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1237884" MatName="mat4" Status="Busy">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1237885" MatName="mat4" Status="Free">
        <exam>
        </exam>
      </Infos>
      <Infos InfosID="1237886" MatName="EX-11445GF" QTY="40" Status="Busy">
        <exam>
        </exam>
      </Infos>
    </Informations>
  </Order>
</Orders>


Please how can i get the Parents attributs where Status = "Busy" that means OrderID Priority, InfosID, and MatName. i didnt found a good request. hier ist my request

C#
var InfosAttribut = from xml in xdoc.Descendants("Infos")
                                    where (string)xml.Attribute("Status") == "Busy"
                                    select xml.Attributes();

with this LinQ Request i just get Attribut of Tag "Infos" but i want to get all this Thing in one time. is it possible?
thx
Posted

1 solution

In your LINQ query xml refers to the Infos element. You could do this instead:

C#
var InfosAttribut = from xml in xdoc.Descendants("Order")
                                    where xml.Descendants("Info").Any(d => (string)d.Attribute("Status") == "Busy")
                                    select xml.Attributes();


xml will now refer to the Order element, and a check is done whether there is any Infos element marked as Busy.
 
Share this answer
 
Comments
stefan from germany 30-Jul-13 10:35am    
thx Mo with it i get exactly what i want

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900