Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
This is my XML file i had two child elements.among them i need to read any only one particular element and its inner elements type, can any one help me.



XML
<?xml version="1.0" encoding="utf-8" ?><big></big>

<appSettings>

<mail>
     <add key="ColourOrange" value="" type="URL"/>
     <add key="SMTP_Port" value="" type="URL"/>
     

</mail>


<map>
            
     <add key="MapCenterX" value="" type="NUMERIC"/>
     <add key="MapCenterY" value="" type="NUMERIC"/>
     <add key="Radius" value="" type="NUMERIC"/>
  
</map>

</appSettings>
Posted
Comments
Andy Lanng 14-Jun-13 6:08am    
have you looked in to how this is done programatically, with XmlDocument for example: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument(v=vs.100).aspx
I need more information on how you are handling this xml in the first place to help any more 0.o
Marius Bancila 14-Jun-13 7:01am    
Why do you tag with C and post in the C++ section if you need this in C#?

C#
XmlDocument xDoc = new XmlDocument();
xDoc.Load(yourXMLDocumentPath);

XmlNode oneNode = xDoc.SelectSingleNode("appSettings/mail"); // or whatever else

foreach(XmlNode iNode in oneNode.ChildNodes) {
  // scan your <mail> element or whatever else
}
 
Share this answer
 
v2
Refer similar thread[^]
 
Share this answer
 
if the problem is to get appSettings, read this article Custom-Configuration-Sections-for-Lazy-Coders
 
Share this answer
 
try this'

XML
XElement xelement = XElement.Load(@"C:\.........xml");
           IEnumerable<XElement> menus = xelement.Elements();
           List<string> subMenuList = new List<string>();
           foreach (var menu in menus)
           {
               if (menu.Attribute("id").Value == "......")
               {
                   foreach (var submenu in menu.Elements())
                   {
                       subMenuList.Add(submenu.Attribute("name").Value);
                   }
               }
           }
 
Share this answer
 

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