473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Search XML file using C# Asp.net

7
Hi

I had a quick question - How do I use Xpath to search the following xml file? Or should I be using something else? Pls note that the file has xml empty tags.

xml file
<World>
<Country Name ="Denmark"/>
<Country Name ="Hungry"/>
</World>

I tried the following code in C# ASP.net

Expand|Select|Wrap|Line Numbers
  1. XmlDocument doc = new XmlDocument();
  2. doc.Load("C:\\world.xml");
  3. XmlNodeList nodeList;
  4. XmlNode root = doc.DocumentElement;
  5. nodeList = root.SelectNodes("World/[Country Name='Denmark']");
and it showed the following error
Expression must evaluate to a node-set. .The error occured at the last line(5)

I would like the node list to have 'Denmark'. I highly appreciate any kind of suggestion.

Thanks
Kim
Oct 21 '07 #1
2 1701
newasp
7
HI
I figured it ....

The query should be
XmlNodeList nodeList = xmlDoc.SelectNodes("//Country[@Name = ' Denmark']");

Now my question is

Suppose I have a string variable that reads the string entered by the user in the textbox , how can I write the query without hard coding the country name?

Thanks
Kim
Oct 21 '07 #2
jhardman
3,406 Expert 2GB
moved to .NET forum
Oct 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
3
by: RiceGuy | last post by:
Hi! I'm looking for ideas on what would the best approach to design a search system for a RSS feeds. I will have some 50 RSS feeds (all RSS 2.0 compliant) stored locally on the web server. Now I'm...
1
by: Filip | last post by:
Hi All, a while ago I had to write a asp.net search application. The start page is a html page, which calls a aspx file that shows the search results, using a datagrid. So far no problem. But:...
13
by: Ray Muforosky | last post by:
Hello all: Task: I want to do file search, using the "conatining text" option from a web page. How do I search for a file on my local drive containing a certain string, from a web page. That...
4
by: zakhirn | last post by:
Hello, I have an extremely new user to XML and XSL, and I would like to know how to search XML data via a input form in HTML, and have the results displayed in HTML. If anyone has code that...
4
by: Dameon | last post by:
Hi All, I have a process where I'd like to search the contents of a file(in a dir) for all occurences (or the count of) of a given string. My goal is to focus more on performance, as some of the...
8
by: stunna | last post by:
Hi there, i want to implement a a system to search for a file in a folder using the file name and if its there, i want it to be displayed. I have one through a couple of books on how to implement...
4
by: ravindarjobs | last post by:
hi...... i am using ms access 2003,vb6 i have a form. in that i have 2 buttons 1. start search 2 stop search when i click the "start search" button the fucntion SearchSystem() is called,...
3
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.