Is this what you are trying to do:

static void TestLinq2XMLSelectUsingAttributeValue()
{
    XElement credentials = new XElement("Credentials",
        MakeCredentialElement("yyyS", "7118"),
        MakeCredentialElement("CompanyName", "Services Pty Ltd"),
        MakeCredentialElement("ABN", "123456"),
        MakeCredentialElement("BranchID", "22270"),
        MakeCredentialElement("Name", "ZZ"));
    var branchId = credentials.Descendants("Credential").Where(c =>  
c.Attribute("domain").Value == "BranchID").SingleOrDefault();

    if (branchId != null)
        Console.WriteLine(branchId.Value);
    else
        Console.WriteLine("not found");
}

static XElement MakeCredentialElement(string domain, string identity)
{
    return new XElement("Credential", new XAttribute("domain", domain), 
identity);
}


writes out 22270

-----Original Message-----
From: [email protected]
Sent: 2/6/2012 4:00 PM

<Credential domain="yyyS">

<Identity>7118</Identity>

</Credential>

<Credential domain="CompanyName">

<Identity> Services Pty Ltd</Identity>

</Credential>

<Credential domain="ABN">

<Identity>123456</Identity>

</Credential>

<Credential domain="BranchID">

<Identity>22270</Identity>

</Credential>

<Credential domain="Name">

<Identity>ZZ</Identity>

</Credential>

How do i get the SBranchID?  I can 
useLinq.XElement.Parse(rt2).<From>.<Credential>(3).<Identity>.Value but what if 
i do not know the sequence?

Anthony


Reply via email to