Subscribe to Subscribers
Talk to Webmaster Tony John


Resources » .NET programming » XML

How to check whether element value at any XPath is alphanumeric or not.


Posted Date:     Category: XML    
Author: Member Level: Gold    Points: 15


This class library will help user to find the element value is alphanumeric or not. User has to mention the XML file and XPath. Regular expression is used to check alphanumeric values. Result will be returned as true or false.



 


How to check whether element value at any XPath is alphanumeric or not.<BR>
You have to create a class library and place following code in to it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;

namespace yournamespace.subfoldername
{
class DoCheckAlphanueric
{
public bool chkelementvalueaphanumeric(string yourXMLfile, string yourXPathValue)
{
bool result = false;
XmlDocument doc = new XmlDocument();
doc.Load(yourXMLfile);
XmlNodeList myNodeList = doc.SelectNodes(yourXPathValue);
foreach (XmlNode myNode in myNodeList)
{
Regex pattern = new Regex("^[a-zA-Z0-9]*$");
string[] result = myNode.InnerText.Trim().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in result)
{
if (pattern.IsMatch(s))
{
result = true;
return result;
}
else
{
result = false;
}
}
}
return result;
}

}
}






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


Responses to "How to check whether element value at any XPath is alphanumeric or not."

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: To create Xml using xmldocument,xmlwriter and xmltextreader
    Previous Resource: How to use regular expression validation for value at user defined XPAth in XML file?
    Return to Resources
    Post New Resource
    Category: XML


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    XML  .  



    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.