none
How to get attribute value based on input attribute value. Please help its very urgent. thanks in advance

    Question

  • i have one xml file which have below data, i need to give Name attribute and need to get Heirarchy attribute value.

    please give me c# code for this(linq to xml  or other approach)

    for example:

    input: LoginUserName

    output: LogInWindow,textBox_UserName

    input: PatientCreateName

    output: PatienceLogInWindow,textBox_UserName


    <UIW>
     
      <Login  Name="LogInWindow" Heirarchy="Login">
        <UserName  Name="LoginUserName" Heirarchy="LogInWindow,textBox_UserName" Type="Edit"/>
        <Password  Name="LoginPassword" Heirarchy="LogInWindow,textBox_Password" Type="Edit"/>
        <Button  Name="LoginButton" Heirarchy="LogInWindow,OKButton" Type="Edit"/>
      </Login>
     
      <PatientCreate  Name="Sample1" Heirarchy="LogInWindow">
        <UserName  Name="PatientCreateName" Heirarchy="PatienceLogInWindow,textBox_UserName" Type="Edit"/>
        <Password  Name="PatientLoginUserName" Heirarchy="LogInWindow,textBox_UserName" Type="Edit"/>
        <Button  Name="PatientLoginUserButton" Heirarchy="LogInWindow,textBox_UserName" Type="Edit"/>
      </PatientCreate>
     
    </UIW>

    Friday, June 13, 2014 4:45 AM

All replies

  • Hope this helps..

        XDocument objDoc = XDocument.Load(@"C:\temp\data.xml");
                var input = "LoginUserName";
                //do needed exception handling for null
                XElement query = objDoc.Descendants().Attributes().Where(x => x.Value == input).ElementAt(0).Parent;
                Console.WriteLine(" {0} ", query.Attribute("Heirarchy").Value);
    

    Thursday, June 19, 2014 4:30 PM