Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

More...


Resources » Code Snippets » C# Syntax

How to check whether a character is present in the value of given XPath of XML file?


Posted Date:     Category: C# Syntax    
Author: Member Level: Gold    Points: 15


There is a sample code to check whether any particular character is present in XPath in xml file or not. User can set xpath , expected character and xml file dynamically to check this. Code has been developed in C# whereas application is windows based.



 


How to check whether a character is present in the value of given XPath of XML file?
Introduction
I have developed the method which will give you true as a result, if expected character is present in the XPath of XML file. If that character is not present in xpath of xml file then it will give false as a result.
User has to give parameters as xpathvalue , xml file path , expected character in the method.
Description
Create a class library in which put this code snippet and call whenever it is required.


public bool IsCharacterPresent(string xpathvalue, string user_defined_xml_file , string expected_Character)
{
bool result_value = false;
try
{
XmlDocument user_defined_xml_document = new XmlDocument();
user_defined_xml_document.Load(user_defined_xml_file);
XmlNodeList mynodeValueList = user_defined_xml_document.SelectNodes(xpathvalue);
foreach (XmlNode mynodeValue in mynodeValueList)
{

if (mynodeValue.InnerText.Contains(expected_Character))

{
result_value = true;
return result_value;
}
else
{
result_value = false;

}
}

}
catch (Exception)
{
result_value = false;
}

return result_value;
}

Instead of a character, suppose user wants to put substring then also this method can be used.





Did you like this resource? Share it with your friends and show your love!


Responses to "How to check whether a character is present in the value of given XPath of XML file?"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to check whether expected element value is present in XPath in user defined XML file.
    Previous Resource: How to check whether a expected element value length is present in the value of given XPath of XML
    Return to Resources
    Post New Resource
    Category: C# Syntax


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.