dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersMore...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » Code Snippets » C# Syntax

How to check whether a expected element value length is present in the value of given XPath of XML


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


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



 


How to check whether a expected element value length 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 element value length is present in the XPath of XML file. If that expected element value length 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 element value length in the method.
Description
Create a class library in which put this code snippet and call whenever it is required.

public bool Match_element_value_length (string user_defined_xpath, string user_defined_xml_file, string user_defined_expected_length)
{
bool result_val = false;
XmlDocument user_defined_xml_doc = new XmlDocument();
user_defined_xml_doc.Load(user_defined_xml_file);
XmlNodeList my_nodeList = user_defined_xml_doc.SelectNodes(user_defined_xpath);
foreach (XmlNode my_node in my_nodeList)
{
if (Convert.ToString(my_node.InnerText.Length) == user_defined_expected_length)
{
result_val = true;
return result_val;
}
else
{
result_val = false;


}
}

return result_val;
}





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


Responses to "How to check whether a expected element value length is present in the value of given XPath of XML"

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 a character is present in the value of given XPath of XML file?
    Previous Resource: How to download and Upload data to any REST Service (Synchronous)
    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
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    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.