getting values from xml file

Posted on 2005-05-02
Last Modified: 2010-04-07
this is my xml.
i need to write c# code that get as parameters the category id
and language id and retrive the full path category:

input :1,125 langID,catID
output : Books > Drama

input : 2,127
output : Countries > spain

the categories are only 2 level : parent or not parent


<?xml version="1.0" encoding="utf-8" ?>
<Language id="1">
      <parentCat id="1" name="Books"/>
      <subCat id="123" name="sience fiction"/>
      <subCat id="124" name="comedy"/>
      <subCat id="125" name="Drama"/>

<Language id="2">
      <parentCat id="2" name="Countries"/>
      <subCat id="126" name="us"/>
      <subCat id="127" name="uk"/>
      <subCat id="128" name="spain"/>

Question by:eladr
    1 Comment
    LVL 52

    Accepted Solution

    Heres a quick example:

       string langid = "1";
       string catid  = "125";
       string result = "";

       string xpath = string.Format("//Language[@id='{0}']/subCat[@id='{1}']", langid, catid);

       XmlDocument xml = new XmlDocument();
       xml.Load("your xml document");
       XmlNode node = xml.SelectSingleNode(xpath);

       if ( node != null )
          result = string.Format("{0} > {1}", node.ParentNode.FirstChild.Attributes["name"].Value , node.Attributes["name"].Value);
          result = "No match found: " + xpath;

    Hope this helps.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
    This video discusses moving either the default database or any database to a new volume.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now