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:
XML
<Messages>
  <category Name="Main">
    <message name="Name 3"><![CDATA[<category Name="Main"> <message id="1" title="one" name="Name1" Description="Description1"> </message> </category>]]></message>
Posted
Updated 15-Jul-13 0:12am
v2

1 solution

Create A Messages.cs Class

C#
public class Message
{
    [Required]
    public string Name { get; set; }
    [Required]
    public string Description { get; set; }
}   


C#
XmlNodeList xmlDescriptionNodes = xmlDoc.GetElementsByTagName("message");

if (xmlDescriptionNodes != null)
{
    foreach (XmlNode xmlNode in xmlDescriptionNodes)
    {
        // Get The Innertext of The Message Xelement 
        string Description = Convert.ToString(xmlNode.InnerText);
        bool IsContain = Description.Contains(name); // Check Wether the input string Name is there in innertext or not 
        if (IsContain == true) // if Contains It returns true 
        {
            Message message = new Message();
            message.Name = Convert.ToString(xmlNode.Attributes["name"].Value);
            message.Description = Convert.ToString(xmlNode.InnerText);
            lmessage.Add(message); // Add All The Messages to the List for Display purpose 
        }
    }
}
 
Share this answer
 
v3
Comments
StM0n 15-Jul-13 7:26am    
Code could be slightly cleaner, but nonetheless have a five

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