[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

getting values from xml file

this is my xml.
i need to write asp.net c# code that get as parameters the category id
and language id and retrive the full path category:
example:

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

input : 2,127
output : Countries > spain

the categories are only 2 level : parent or not parent

10x

<?xml version="1.0" encoding="utf-8" ?>
<CategoryData>
<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>

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


</CategoryData>
0
eladr
Asked:
eladr
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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);
   else
      result = "No match found: " + xpath;

Hope this helps.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now