Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How can i get the xml data by using keyword like search.

1--> i have 1 xml file with data.(one.xml)

2--> uploaded the one.xml file
3--> i have one textbox and button.
4--> i am given to one key word in textbox ex-2

now how to get the related data for XML file

my XML file

XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<company>
  <employee id="109">
    <fname>Nohn</fname>
    <lname>Graph</lname>
    <age>28</age>
  </employee>
  <employee id="110">
    <fname>Anna</fname>
    <lname>Laoe</lname>
    <age>32</age>
  </employee>
  <employee id="111">
    <fname>Nllan</fname>
    <lname>Woods</lname>
    <age>25</age>
  </employee>
  <employee id="113">
    <fname>Greg</fname>
    <lname>Muray</lname>
    <age>24</age>
  </employee>
  <employee id="114">
    <fname>Fannie</fname>
    <lname>Now</lname>
    <age>36</age>
  </employee>
  <employee id="115">
    <fname>Hello</fname>
    <lname>World</lname>
    <age>11</age>
  </employee>
  <employee id="116">
    <fname>What</fname>
    <lname>How</lname>
    <age>11</age>
  </employee>
</company>


1) my search keyword is '2'

2) My Search Keyword is 'N'
then show the XML data related to my keyword

1 like o/p
28
32
25


2 like o/p
Nohn
Nllan
Now


please help me

thanks and regards
Posted
Updated 5-Sep-13 1:46am
v2

You first need to define which fields to use in your query.

You may load the document into one instance of XmlDocument. This snipped could help:
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load( "Put here your file name" );

XmlNodeList Nodes = XmlDoc.SelectNodes( "put here your XPath query/filter" );

foreach (XmlNode Node in Nodes)
{ 
    /// And do something usefull for you with the results... if any ;-)
}


There's a guide into XPath here: http://www.w3schools.com/xpath/[^].
 
Share this answer
 
Try this code

C#
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.LoadXml(x);

XmlNodeList Nodes = XmlDoc.SelectNodes("//text()[contains(.,'N')]");

foreach (XmlNode Node in Nodes)
{
     Console.WriteLine(Node.InnerText);
}
 
Share this answer
 

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