473,320 Members | 2,092 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,320 software developers and data experts.

Querying in an XML file

Hi,

I have the XML file shown below.

Now I am trying to retrieve all the 'Event' nodes using XPath. The
code being used is shown below.

The output being ouput is the data in the SubNodes given as one string.

(Output shown below)

Is there a way how to iterate through the sub-nodes(From, To,
Lookahaed). What I was doing is three different XPathExpressions for
each sub-node, but I think thats not very effecient.

Can someone help me out
Thanks in Advance
/* code */
StreamReader reader = new StreamReader(filePath, Encoding.UTF8);
XPathDocument doc = new XPathDocument(reader);
XPathNavigator nav = doc.CreateNavigator();

XPathExpression xpe = nav.Compile("Simulation/Events/Event");
XPathNodeIterator xpni = nav.Select(xpe);

while(xpni.MoveNext())
{
Console.WriteLine(xpni.Current.Value.ToString());
}
/* Output */
S1S21
S3S11
S2S31
S3S21

/* Sample of xml file */
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Simulation>
<States>
<State>S1</State>
<State>S2</State>
<State>S3</State>
</States>
<Events>
<Event>
<From>S1</From>
<To>S2</To>
<Lookahaed>1</Lookahaed>
</Event>
<Event>
<From>S3</From>
<To>S1</To>
<Lookahaed>1</Lookahaed>
</Event>
<Event>
<From>S2</From>
<To>S3</To>
<Lookahaed>1</Lookahaed>
</Event>
<Event>
<From>S3</From>
<To>S2</To>
<Lookahaed>1</Lookahaed>
</Event>
</Events>
<Instances />
</Simulation>

Mar 25 '06 #1
0 967

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

Similar topics

6
by: Greg | last post by:
I am working on a project that will have about 500,000 records in an XML document. This document will need to be queried with XPath, and records will need to be updated. I was thinking about...
2
by: Richard L Rosenheim | last post by:
I loaded a XSLT stylesheet into a XMLDocument to retrieve some of the data. I received an exception when the SelectNodes method was invoked. The message was "System.Xml.XPath.XPathException -...
0
by: Chris | last post by:
Hi all, I have a web site which allows our customers to write data via forms into an access table stored on our ISP's remote server. My question is how do I efficiently retrieve the data? ISP...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
0
by: roiavidan | last post by:
Hi, I'm having a bit of a problem with a small application I wrote in C#, which uses an Access database (mdb file) for storing financial data. After looking for a similiar topic and failing to...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: Job Lot | last post by:
i am querying excel file as follows Dim conn As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; " & _ "data source='" & "C:\Temp\SSPortfolio.xls" & " '; " & _ "Extended Properties=Excel...
5
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an...
2
by: RajSharma | last post by:
Hi, I am facing a problem regarding querying thru a large table having millions of rows....... Its hanging in between while querying for all those rows Can anybody suggest me a query regarding :...
16
Dököll
by: Dököll | last post by:
Hey Gang! I just ran through a wonderful Microsoft video for VS 2005 Web Dev and SQL 2005 Express. Data added to SQL .mdf file through VS web site... How does one query the data in the SQL...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.