473,513 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML file and SearchNode

Hi all
I have large XML file (5 levels of RootNode.ChildNodes.ChildNodes... and so
on... Of course XmlType are Text and Atributs) and I must search in it some
elements by various criteria. I think about "my privet method
SelectXmlElement", but it's not so easy. To much levels for "foreach" or
other IEnumerable...

So before I implement this "horrible" method(s) I have one question. Is
something in VS.Net to auto search in XML? I read some about XPath, but it's
look like strange magic...

But if XPath is reason -> please, just one simple example will be helpfull

Regards
Krzysztof
Nov 15 '05 #1
2 1250
Hi,
You could use XPath for XML search. Below is several simple examples:

Let our data.xml file contains:
<mytag>
<mytag2>
<mysubtag val="abc"/>
</mytag2>
<mysubtag val="def"/>
</mytag>"

XPathDocument doc = new XPathDocument("data.xml");
// Search for all <mysubtag/> elements
XPathNavigator n = doc.CreateNavigator();
XPathNodeIterator iter = n.Select("//mysubtag");
while (iter.MoveNext())
{
// execute some processing for node iter.Current
}
//--------------------------------------------------------
XPathDocument doc = new XPathDocument("data.xml");
// Search for all <mysubtag/> elements where val is "abc"
XPathNavigator n = doc.CreateNavigator();
XPathNodeIterator iter = n.Select("//mysubtag[@val = 'abc']");
while (iter.MoveNext())
{
// execute some processing for node iter.Current
}
//--------------------------------------------------------
XPathDocument doc = new XPathDocument("data.xml");
// Search for all <mysubtag/> elements inside <mytag2>
XPathNavigator n = doc.CreateNavigator();
XPathNodeIterator iter = n.Select("//mytag2/mysubtag");
while (iter.MoveNext())
{
// execute some processing for node iter.Current
}

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Krzysztof" <kk******@poczta.onet.pl> wrote in message
news:bm**********@news.onet.pl...
Hi all
I have large XML file (5 levels of RootNode.ChildNodes.ChildNodes... and so on... Of course XmlType are Text and Atributs) and I must search in it some elements by various criteria. I think about "my privet method
SelectXmlElement", but it's not so easy. To much levels for "foreach" or
other IEnumerable...

So before I implement this "horrible" method(s) I have one question. Is
something in VS.Net to auto search in XML? I read some about XPath, but it's look like strange magic...

But if XPath is reason -> please, just one simple example will be helpfull

Regards
Krzysztof

Nov 15 '05 #2
[cut]
Thanks that's it!
Regards
Krzysztof
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3911
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in...
5
5436
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. I want to develop a webpage where people can send attachments that are stored on their local PC.
7
3517
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite...
3
26242
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
0
3911
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
13
4283
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I...
1
5356
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried,...
3
3151
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can I find a list of all the types which can be returned? For example, if it is a Word document will it return "document/doc".
0
2538
by: troutbum | last post by:
I am experiencing problems when one user has a document open through a share pointing to the web site. I use the dsolefile to read the contents of a particular directory and then display them in a datalist. When the next user selects trys to run the page, the page fails and I get a generic error message from the stack trace. I am assuming...
0
7178
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
473
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.