jay jay - 1 year ago 56
ASP.NET (C#) Question

Searching xml attribute having similar values

I have an xml

<?xml version="1.0" encoding="utf-8"?>
<field title="Year">
<description>Numeric data</description>
<field title="mail">
<description>Numeric data</description>
<field title="Years">
<description>AlphNumeric Data</description>

using below code Im extracting node values of
that comes under attribute Title with Value='year'

XmlDocument xml = new XmlDocument();
XmlNodeList xnList = xml.SelectNodes("/contentr/field[@title='"+ searchdata +"']");

if searchdata = 'year' then
this will extract only node values of attribute with value 'year'.But i need to extract all data with attribute value contains 'year' as well as 'years'

is there anyway to achieve this ? iam working on c# ,ver 2.0

Answer Source

Use the contains() function:

xml.SelectNodes("/content/field[contains(@title,'" + searchdata + "')]")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download